root/trunk/lodepng/lodepng/util.d

Revision 201, 1.8 kB (checked in by Lutger, 11 months ago)

Removed recode, added /examples/recoder. Small changes to Encode. Fixes and additions for editing.

Line 
1 /// utility and some wrappers for tango / phobos compatibility
2 module lodepng.util;
3
4
5     //////////////////////////////////////////////////////////////////////////////////////
6     //                                                                                  //
7     //  This module provides some utility functions internal to lodepng and wraps or    //
8     //  aliases a few phobos / tango dependent functions under a common api             //
9     //                                                                                  //
10     //////////////////////////////////////////////////////////////////////////////////////
11
12 version(Tango)
13 {
14     import tango.stdc.stringz;
15     import tango.text.Util;
16
17     char[] _enforce(T)(char[] cond, char[] msg)
18     {
19         // HACK
20         return `if (!(`~ cond ~`)) throw new `~ T.stringof ~` ( "`~ cond ~`: `~ msg ~` (in " ~
21                 `~ `__FILE__` ~` ~ ")" );`;
22     }
23
24     /+ TODO: implement this with toString
25     char[] _enforce(T)(char[] cond, char[] msg)
26     {
27         // HACK
28         return `if (!(`~ cond ~`)) throw new `~ T.stringof ~` ( "`~ cond ~`: `~ msg ~` (in " ~
29                 `~ `__FILE__` ~` ~ " at " ~ `~ `ToString!(__LINE__)` ~` ~ ")" );`;
30     }
31     +/
32
33     alias toStringz toCString;
34     alias tango.text.Util.locate!(char, char) strFind;
35
36 }
37 else
38 {
39     public import std.metastrings;
40     import std.string;
41
42
43     char[] _enforce(T)(char[] cond, char[] msg)
44     {
45        return std.metastrings.Format!
46        (
47             `if (!(%s)) throw new %s (        "%s: %s (in " ~ %s ~ " at " ~ %s ~ ")" );`,
48                    cond,          T.stringof, cond,msg,      `__FILE__`,   `std.metastrings.ToString!(__LINE__)`
49        );
50     }
51
52
53
54     alias std.string.find strFind;
55     alias toString toCString;
56 }
Note: See TracBrowser for help on using the browser.