1 /*
2 
3 Boost Software License - Version 1.0 - August 17th, 2003
4 
5 Permission is hereby granted, free of charge, to any person or organization
6 obtaining a copy of the software and accompanying documentation covered by
7 this license (the "Software") to use, reproduce, display, distribute,
8 execute, and transmit the Software, and to prepare derivative works of the
9 Software, and to permit third-parties to whom the Software is furnished to
10 do so, all subject to the following:
11 
12 The copyright notices in the Software and this entire statement, including
13 the above license grant, this restriction and the following disclaimer,
14 must be included in all copies of the Software, in whole or in part, and
15 all derivative works of the Software, unless such copies or derivative
16 works are solely in the form of machine-executable object code generated by
17 a source language processor.
18 
19 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
22 SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
23 FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
24 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 DEALINGS IN THE SOFTWARE.
26 
27 */
28 module derelict.util.compat;
29 
30 version(D_Version2)
31 {
32     mixin("alias const(char)* CCPTR;");
33     mixin("alias const(wchar)* CWCPTR;");
34     mixin("alias const(dchar)* CDCPTR;");
35     mixin("alias const(ubyte)* CUBPTR;");
36     mixin("alias const(void)* CVPTR;");
37     mixin("alias immutable(char)* ICPTR;");
38 }
39 else
40 {
41     alias char* CCPTR;
42     alias wchar* CWCPTR;
43     alias dchar* CDCPTR;
44     alias ubyte* CUBPTR;
45     alias void* CVPTR;
46     alias char* ICPTR;
47 }
48 
49 version(D_Version2) 
50 {
51 	public import core.stdc.config : c_long, c_ulong; 
52 }
53 else version(Tango)
54 {
55 	version (Windows)
56 	{
57 		alias int c_long;
58 		alias uint c_ulong;
59 	}
60 	else
61 	{
62 		static if((void*).sizeof > (int).sizeof)
63 		{
64 			alias long c_long;
65 			alias ulong c_ulong;
66 		}
67 		else
68 		{
69 			alias int c_long;
70 			alias uint c_ulong;
71 		}
72 	}
73 }
74 
75 version(D_Version2)
76 {
77 	version(Posix)
78 	{
79 		public import core.sys.posix.sys.types : off_t;
80 	}
81 	else
82 	{
83 		alias c_long off_t;
84 	}
85 }
86 else
87 {
88 	alias c_long off_t;
89 }
90 
91 version(Tango)
92 {
93     private
94     {
95         import tango.stdc.string;
96         import tango.stdc.stringz;
97         import tango.text.Util;
98         import tango.core.Version;
99     }
100 
101     version (PhobosCompatibility) {}
102     else
103     {
104         alias char[] string;
105         alias wchar[] wstring;
106         alias dchar[] dstring;
107     }
108 }
109 else
110 {
111     private
112     {
113         version(D_Version2)
114         {
115             import std.conv;
116         }
117         import std.string;
118         import std.c.string;
119     }
120  
121 }
122 
123 template gsharedString ()
124 {
125     version (D_Version2)
126         const gsharedString = "__gshared: ";
127 
128     else
129         const gsharedString = "";
130 }
131 
132 CCPTR toCString(string str)
133 {
134     return toStringz(str);
135 }
136 
137 string toDString(CCPTR cstr)
138 {
139     version(Tango)
140     {
141         return fromStringz(cstr);
142     }
143     else
144     {
145         version(D_Version2)
146         {
147             mixin("return to!string(cstr);");
148         }
149         else
150         {
151             return toString(cstr);
152         }
153     }
154 }
155 
156 int findStr(string str, string match)
157 {
158     version(Tango)
159     {
160         int i = locatePattern(str, match);
161         return (i == str.length) ? -1 : i;
162     }
163     else
164     {
165         version(D_Version2)
166         {
167             mixin("return cast(int)indexOf(str, match);");
168         }
169         else
170         {
171             return find(str, match);
172         }
173     }
174 }
175 
176 string[] splitStr(string str, string delim)
177 {
178     return split(str, delim);
179 }
180 
181 string stripWhiteSpace(string str)
182 {
183     version(Tango)
184     {
185         return trim(str);
186     }
187     else
188     {
189         return strip(str);
190     }
191 }
192