Mercurial > projects > dwt2
comparison java/src/java/mangoicu/ICU.d @ 21:9b96950f2c3c
the 'java' tree compiles on both D1-Tango and D2-Phobos
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 19 Mar 2009 20:38:55 +0100 |
parents | dbfb303e8fb0 |
children | f589fc20a5f9 |
comparison
equal
deleted
inserted
replaced
20:dccb717aa902 | 21:9b96950f2c3c |
---|---|
40 | 40 |
41 *******************************************************************************/ | 41 *******************************************************************************/ |
42 | 42 |
43 module java.mangoicu.ICU; | 43 module java.mangoicu.ICU; |
44 | 44 |
45 import java.lang.util; | |
45 /******************************************************************************* | 46 /******************************************************************************* |
46 | 47 |
47 Library version identifiers | 48 Library version identifiers |
48 | 49 |
49 *******************************************************************************/ | 50 *******************************************************************************/ |
50 | 51 |
51 version (ICU30) | 52 version (ICU30) |
52 { | 53 { |
53 private static const final char[] ICULib = "30"; | 54 private static const char[] ICULib = "30"; |
54 private static const final char[] ICUSig = "_3_0\0"; | 55 private static const char[] ICUSig = "_3_0\0"; |
55 } | 56 } |
56 version (ICU32) | 57 version (ICU32) |
57 { | 58 { |
58 private static const final char[] ICULib = "32"; | 59 private static const char[] ICULib = "32"; |
59 private static const final char[] ICUSig = "_3_2\0"; | 60 private static const char[] ICUSig = "_3_2\0"; |
60 } | 61 } |
61 version (ICU34) | 62 version (ICU34) |
62 { | 63 { |
63 private static const final char[] ICULib = "34"; | 64 private static const char[] ICULib = "34"; |
64 private static const final char[] ICUSig = "_3_4\0"; | 65 private static const char[] ICUSig = "_3_4\0"; |
65 } | 66 } |
66 version (ICU36) | 67 version (ICU36) |
67 { | 68 { |
68 private static const final char[] ICULib = "36"; | 69 private static const char[] ICULib = "36"; |
69 private static const final char[] ICUSig = "_3_6\0"; | 70 private static const char[] ICUSig = "_3_6\0"; |
70 } | 71 } |
71 else | 72 else |
72 { | 73 { |
73 private static const final char[] ICULib = "38"; | 74 private static const char[] ICULib = "38"; |
74 private static const final char[] ICUSig = "_3_8\0"; | 75 private static const char[] ICUSig = "_3_8\0"; |
75 } | 76 } |
76 | 77 |
77 /******************************************************************************* | 78 /******************************************************************************* |
78 | 79 |
79 *******************************************************************************/ | 80 *******************************************************************************/ |
175 | 176 |
176 /*********************************************************************** | 177 /*********************************************************************** |
177 | 178 |
178 ***********************************************************************/ | 179 ***********************************************************************/ |
179 | 180 |
180 package static final void exception (char[] msg) | 181 package static final void exception (CString msg) |
181 { | 182 { |
182 throw new ICUException (msg); | 183 throw new ICUException ( cast(String)msg); |
183 } | 184 } |
184 | 185 |
185 /*********************************************************************** | 186 /*********************************************************************** |
186 | 187 |
187 ***********************************************************************/ | 188 ***********************************************************************/ |
188 | 189 |
189 package static final void testError (UErrorCode e, char[] msg) | 190 package static final void testError (UErrorCode e, CString msg) |
190 { | 191 { |
191 if (e > 0) | 192 if (e > 0) |
192 exception (msg); | 193 exception (msg); |
193 } | 194 } |
194 | 195 |
195 /*********************************************************************** | 196 /*********************************************************************** |
196 | 197 |
197 ***********************************************************************/ | 198 ***********************************************************************/ |
198 | 199 |
199 protected static final char* toString (char[] string) | 200 package static final char* toString (CString string) |
200 { | 201 { |
201 static char[] empty = ""; | 202 static char[] empty; |
202 | 203 |
203 if (! string.length) | 204 if (! string.length) |
204 return (string.ptr) ? empty.ptr : null; | 205 return (string.ptr) ? empty.ptr : null; |
205 | 206 |
206 // if (* (&string[0] + string.length)) | 207 // if (* (&string[0] + string.length)) |
209 char[] copy = new char [string.length + 1]; | 210 char[] copy = new char [string.length + 1]; |
210 copy [0..string.length] = string; | 211 copy [0..string.length] = string; |
211 copy [string.length] = 0; | 212 copy [string.length] = 0; |
212 string = copy; | 213 string = copy; |
213 } | 214 } |
214 return string.ptr; | 215 return cast(char*)string.ptr; |
215 } | 216 } |
216 | 217 |
217 /*********************************************************************** | 218 /*********************************************************************** |
218 | 219 |
219 ***********************************************************************/ | 220 ***********************************************************************/ |
220 | 221 |
221 protected static final wchar* toString (wchar[] string) | 222 package static final wchar* toString (CString16 string) |
222 { | 223 { |
223 static wchar[] empty = ""; | 224 static wchar[] empty; |
224 | 225 |
225 if (! string.length) | 226 if (! string.length) |
226 return (string.ptr) ? empty.ptr : null; | 227 return (string.ptr) ? empty.ptr : null; |
227 | 228 |
228 // if (* (&string[0] + string.length)) | 229 // if (* (&string[0] + string.length)) |
231 wchar[] copy = new wchar [string.length + 1]; | 232 wchar[] copy = new wchar [string.length + 1]; |
232 copy [0..string.length] = string; | 233 copy [0..string.length] = string; |
233 copy [string.length] = 0; | 234 copy [string.length] = 0; |
234 string = copy; | 235 string = copy; |
235 } | 236 } |
236 return string.ptr; | 237 return cast(wchar*)string.ptr; |
237 } | 238 } |
238 | 239 |
239 /*********************************************************************** | 240 /*********************************************************************** |
240 | 241 |
241 ***********************************************************************/ | 242 ***********************************************************************/ |
288 | 289 |
289 Construct exception with the provided text string | 290 Construct exception with the provided text string |
290 | 291 |
291 ***********************************************************************/ | 292 ***********************************************************************/ |
292 | 293 |
293 this (char[] msg) | 294 this (String msg) |
294 { | 295 { |
295 super (msg); | 296 super (msg); |
296 } | 297 } |
297 } | 298 } |
298 | 299 |
327 ***************************************************************/ | 328 ***************************************************************/ |
328 | 329 |
329 protected struct Bind | 330 protected struct Bind |
330 { | 331 { |
331 void** fnc; | 332 void** fnc; |
332 char[] name; | 333 CString name; |
333 } | 334 } |
334 | 335 |
335 /*************************************************************** | 336 /*************************************************************** |
336 | 337 |
337 ***************************************************************/ | 338 ***************************************************************/ |
340 { | 341 { |
341 HANDLE lib = LoadLibraryA (ICU.toString(library)); | 342 HANDLE lib = LoadLibraryA (ICU.toString(library)); |
342 | 343 |
343 foreach (Bind b; targets) | 344 foreach (Bind b; targets) |
344 { | 345 { |
345 char[] name = b.name ~ ICUSig; | 346 auto name = b.name ~ ICUSig; |
346 *b.fnc = GetProcAddress (lib, name.ptr); | 347 *b.fnc = GetProcAddress (lib, cast(char*)name.ptr); |
347 if (*b.fnc) | 348 if (*b.fnc) |
348 {}// printf ("bound '%.*s'\n", name); | 349 {}// printf ("bound '%.*s'\n", name); |
349 else | 350 else |
350 throw new Exception ("required " ~ name ~ " in library " ~ library); | 351 throw new Exception ( cast(String)("required " ~ name ~ " in library " ~ library)); |
351 } | 352 } |
352 return lib; | 353 return lib; |
353 } | 354 } |
354 | 355 |
355 /*************************************************************** | 356 /*************************************************************** |
398 ***************************************************************/ | 399 ***************************************************************/ |
399 | 400 |
400 protected struct Bind | 401 protected struct Bind |
401 { | 402 { |
402 void** fnc; | 403 void** fnc; |
403 char[] name; | 404 CString name; |
404 } | 405 } |
405 | 406 |
406 /*************************************************************** | 407 /*************************************************************** |
407 | 408 |
408 ***************************************************************/ | 409 ***************************************************************/ |
557 ***************************************************************/ | 558 ***************************************************************/ |
558 | 559 |
559 protected struct Bind | 560 protected struct Bind |
560 { | 561 { |
561 void** fnc; | 562 void** fnc; |
562 char[] name; | 563 CString name; |
563 } | 564 } |
564 | 565 |
565 /*************************************************************** | 566 /*************************************************************** |
566 | 567 |
567 ***************************************************************/ | 568 ***************************************************************/ |