comparison dwtx/dwtxhelper/mangoicu/UNormalize.d @ 91:11e8159caf7a

make the mango icu fork work.
author Frank Benoit <benoit@tionex.de>
date Mon, 07 Jul 2008 15:53:07 +0200
parents 040da1cb0d76
children f05207c07a98
comparison
equal deleted inserted replaced
90:7ffeace6c47f 91:11e8159caf7a
80 All trademarks and registered trademarks mentioned herein are the 80 All trademarks and registered trademarks mentioned herein are the
81 property of their respective owners. 81 property of their respective owners.
82 82
83 *******************************************************************************/ 83 *******************************************************************************/
84 84
85 module dwtx.dwthelper.mangoicu.UNormalize; 85 module dwtx.dwtxhelper.mangoicu.UNormalize;
86 86
87 private import dwtx.dwthelper.mangoicu.ICU, 87 private import dwtx.dwtxhelper.mangoicu.ICU,
88 dwtx.dwthelper.mangoicu.UString, 88 dwtx.dwtxhelper.mangoicu.UString,
89 dwtx.dwthelper.mangoicu.ULocale; 89 dwtx.dwtxhelper.mangoicu.ULocale;
90 90
91 /******************************************************************************* 91 /*******************************************************************************
92 92
93 transforms Unicode text into an equivalent composed or 93 transforms Unicode text into an equivalent composed or
94 decomposed form, allowing for easier sorting and searching 94 decomposed form, allowing for easier sorting and searching
218 Normalize a string. The string will be normalized according 218 Normalize a string. The string will be normalized according
219 the specified normalization mode and options 219 the specified normalization mode and options
220 220
221 ***********************************************************************/ 221 ***********************************************************************/
222 222
223 static void normalize (UText src, UString dst, Mode mode, Options o = Options.None) 223 static void normalize (UStringView src, UString dst, Mode mode, Options o = Options.None)
224 { 224 {
225 uint fmt (wchar* dst, uint len, inout Error e) 225 uint fmt (wchar* dst, uint len, inout UErrorCode e)
226 { 226 {
227 return unorm_normalize (src.get.ptr, src.len, mode, o, dst, len, e); 227 return unorm_normalize (src.get.ptr, src.len, mode, o, dst, len, e);
228 } 228 }
229 229
230 dst.format (&fmt, "failed to normalize"); 230 dst.format (&fmt, "failed to normalize");
243 the user may have to put the string in its normalized 243 the user may have to put the string in its normalized
244 form and compare the results. 244 form and compare the results.
245 245
246 ***********************************************************************/ 246 ***********************************************************************/
247 247
248 static Check check (UText t, Mode mode, Options o = Options.None) 248 static Check check (UStringView t, Mode mode, Options o = Options.None)
249 { 249 {
250 Error e; 250 UErrorCode e;
251 251
252 Check c = cast(Check) unorm_quickCheckWithOptions (t.get.ptr, t.len, mode, o, e); 252 Check c = cast(Check) unorm_quickCheckWithOptions (t.get.ptr, t.len, mode, o, e);
253 testError (e, "failed to perform normalization check"); 253 testError (e, "failed to perform normalization check");
254 return c; 254 return c;
255 } 255 }
264 may return "maybe", this function will perform further 264 may return "maybe", this function will perform further
265 tests to arrive at a TRUE/FALSE result. 265 tests to arrive at a TRUE/FALSE result.
266 266
267 ***********************************************************************/ 267 ***********************************************************************/
268 268
269 static bool isNormalized (UText t, Mode mode, Options o = Options.None) 269 static bool isNormalized (UStringView t, Mode mode, Options o = Options.None)
270 { 270 {
271 Error e; 271 UErrorCode e;
272 272
273 byte b = unorm_isNormalizedWithOptions (t.get.ptr, t.len, mode, o, e); 273 byte b = unorm_isNormalizedWithOptions (t.get.ptr, t.len, mode, o, e);
274 testError (e, "failed to perform normalization test"); 274 testError (e, "failed to perform normalization test");
275 return b != 0; 275 return b != 0;
276 } 276 }
293 It is allowed to have dst==left to avoid copying the entire 293 It is allowed to have dst==left to avoid copying the entire
294 left string. 294 left string.
295 295
296 ***********************************************************************/ 296 ***********************************************************************/
297 297
298 static void concatenate (UText left, UText right, UString dst, Mode mode, Options o = Options.None) 298 static void concatenate (UStringView left, UStringView right, UString dst, Mode mode, Options o = Options.None)
299 { 299 {
300 uint fmt (wchar* p, uint len, inout Error e) 300 uint fmt (wchar* p, uint len, inout UErrorCode e)
301 { 301 {
302 return unorm_concatenate (left.get.ptr, left.len, right.get.ptr, right.len, p, len, mode, o, e); 302 return unorm_concatenate (left.get.ptr, left.len, right.get.ptr, right.len, p, len, mode, o, e);
303 } 303 }
304 304
305 dst.format (&fmt, "failed to concatenate"); 305 dst.format (&fmt, "failed to concatenate");
323 allocated temporarily. For FCD strings and short non-FCD 323 allocated temporarily. For FCD strings and short non-FCD
324 strings there is no memory allocation. 324 strings there is no memory allocation.
325 325
326 ***********************************************************************/ 326 ***********************************************************************/
327 327
328 static int compare (UText left, UText right, Options o = Options.None) 328 static int compare (UStringView left, UStringView right, Options o = Options.None)
329 { 329 {
330 Error e; 330 UErrorCode e;
331 331
332 int i = unorm_compare (left.get.ptr, left.len, right.get.ptr, right.len, o, e); 332 int i = unorm_compare (left.get.ptr, left.len, right.get.ptr, right.len, o, e);
333 testError (e, "failed to compare"); 333 testError (e, "failed to compare");
334 return i; 334 return i;
335 } 335 }
349 349
350 ***********************************************************************/ 350 ***********************************************************************/
351 351
352 private static extern (C) 352 private static extern (C)
353 { 353 {
354 uint function (wchar*, uint, uint, uint, wchar*, uint, inout Error) unorm_normalize; 354 uint function (wchar*, uint, uint, uint, wchar*, uint, inout UErrorCode) unorm_normalize;
355 uint function (wchar*, uint, uint, uint, inout Error) unorm_quickCheckWithOptions; 355 uint function (wchar*, uint, uint, uint, inout UErrorCode) unorm_quickCheckWithOptions;
356 byte function (wchar*, uint, uint, uint, inout Error) unorm_isNormalizedWithOptions; 356 byte function (wchar*, uint, uint, uint, inout UErrorCode) unorm_isNormalizedWithOptions;
357 uint function (wchar*, uint, wchar*, uint, wchar*, uint, uint, uint, inout Error) unorm_concatenate; 357 uint function (wchar*, uint, wchar*, uint, wchar*, uint, uint, uint, inout UErrorCode) unorm_concatenate;
358 uint function (wchar*, uint, wchar*, uint, uint, inout Error) unorm_compare; 358 uint function (wchar*, uint, wchar*, uint, uint, inout UErrorCode) unorm_compare;
359 } 359 }
360 360
361 /*********************************************************************** 361 /***********************************************************************
362 362
363 ***********************************************************************/ 363 ***********************************************************************/