comparison dwtx/dwtxhelper/mangoicu/URegex.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.URegex; 85 module dwtx.dwtxhelper.mangoicu.URegex;
86 86
87 private import dwtx.dwthelper.mangoicu.ICU; 87 private import dwtx.dwtxhelper.mangoicu.ICU;
88 88
89 public import dwtx.dwthelper.mangoicu.ULocale, 89 public import dwtx.dwtxhelper.mangoicu.ULocale,
90 dwtx.dwthelper.mangoicu.UString, 90 dwtx.dwtxhelper.mangoicu.UString,
91 dwtx.dwthelper.mangoicu.UCollator, 91 dwtx.dwtxhelper.mangoicu.UCollator,
92 dwtx.dwthelper.mangoicu.UBreakIterator; 92 dwtx.dwtxhelper.mangoicu.UBreakIterator;
93 93
94 94
95 /******************************************************************************* 95 /*******************************************************************************
96 96
97 Set of slices to return for group matching. See URegex.groups() 97 Set of slices to return for group matching. See URegex.groups()
123 *******************************************************************************/ 123 *******************************************************************************/
124 124
125 class URegex : Groups 125 class URegex : Groups
126 { 126 {
127 private Handle handle; 127 private Handle handle;
128 private UText theText; 128 private UStringView theText;
129 129
130 // Regex modes 130 // Regex modes
131 public enum Flag 131 public enum Flag
132 { 132 {
133 None = 0, 133 None = 0,
166 166
167 ***********************************************************************/ 167 ***********************************************************************/
168 168
169 this (wchar[] pattern, Flag flags=Flag.None, ParseError* pe=null) 169 this (wchar[] pattern, Flag flags=Flag.None, ParseError* pe=null)
170 { 170 {
171 Error e; 171 UErrorCode e;
172 172
173 handle = uregex_open (pattern.ptr, pattern.length, flags, pe, e); 173 handle = uregex_open (pattern.ptr, pattern.length, flags, pe, e);
174 testError (e, "failed to open regex"); 174 testError (e, "failed to open regex");
175 uregex_setText (handle, "", 0, e); 175 uregex_setText (handle, "", 0, e);
176 } 176 }
182 flags. The resulting regular expression handle can then 182 flags. The resulting regular expression handle can then
183 be used to perform various matching operations. 183 be used to perform various matching operations.
184 184
185 ***********************************************************************/ 185 ***********************************************************************/
186 186
187 this (UText pattern, Flag flags=Flag.None, ParseError* pe=null) 187 this (UStringView pattern, Flag flags=Flag.None, ParseError* pe=null)
188 { 188 {
189 this (pattern.get, flags, pe); 189 this (pattern.get, flags, pe);
190 } 190 }
191 191
192 /*********************************************************************** 192 /***********************************************************************
195 195
196 ***********************************************************************/ 196 ***********************************************************************/
197 197
198 private this (Handle handle) 198 private this (Handle handle)
199 { 199 {
200 Error e; 200 UErrorCode e;
201 201
202 this.handle = handle; 202 this.handle = handle;
203 uregex_setText (handle, "", 0, e); 203 uregex_setText (handle, "", 0, e);
204 } 204 }
205 205
232 232
233 ***********************************************************************/ 233 ***********************************************************************/
234 234
235 URegex clone () 235 URegex clone ()
236 { 236 {
237 Error e; 237 UErrorCode e;
238 238
239 Handle h = uregex_clone (handle, e); 239 Handle h = uregex_clone (handle, e);
240 testError (e, "failed to clone regex"); 240 testError (e, "failed to clone regex");
241 return new URegex (h); 241 return new URegex (h);
242 } 242 }
248 248
249 ***********************************************************************/ 249 ***********************************************************************/
250 250
251 UString getPattern () 251 UString getPattern ()
252 { 252 {
253 Error e; 253 UErrorCode e;
254 uint len; 254 uint len;
255 255
256 wchar* x = uregex_pattern (handle, len, e); 256 wchar* x = uregex_pattern (handle, len, e);
257 testError (e, "failed to extract regex pattern"); 257 testError (e, "failed to extract regex pattern");
258 return new UString (x[0..len]); 258 return new UString (x[0..len]);
265 265
266 ***********************************************************************/ 266 ***********************************************************************/
267 267
268 Flag getFlags () 268 Flag getFlags ()
269 { 269 {
270 Error e; 270 UErrorCode e;
271 271
272 Flag f = cast(Flag) uregex_flags (handle, e); 272 Flag f = cast(Flag) uregex_flags (handle, e);
273 testError (e, "failed to get regex flags"); 273 testError (e, "failed to get regex flags");
274 return f; 274 return f;
275 } 275 }
291 Zero length strings are permitted. In this case, no subsequent 291 Zero length strings are permitted. In this case, no subsequent
292 match operation will dereference the text string pointer. 292 match operation will dereference the text string pointer.
293 293
294 ***********************************************************************/ 294 ***********************************************************************/
295 295
296 void setText (UText t) 296 void setText (UStringView t)
297 { 297 {
298 Error e; 298 UErrorCode e;
299 299
300 theText = t; 300 theText = t;
301 uregex_setText (handle, t.get.ptr, t.length, e); 301 uregex_setText (handle, t.get.ptr, t.length, e);
302 testError (e, "failed to set regex text"); 302 testError (e, "failed to set regex text");
303 } 303 }
310 310
311 Note that this returns a read-only reference to the text. 311 Note that this returns a read-only reference to the text.
312 312
313 ***********************************************************************/ 313 ***********************************************************************/
314 314
315 UText getText () 315 UStringView getText ()
316 { 316 {
317 return theText; 317 return theText;
318 } 318 }
319 319
320 /*********************************************************************** 320 /***********************************************************************
358 358
359 ***********************************************************************/ 359 ***********************************************************************/
360 360
361 void group (UString s, uint index) 361 void group (UString s, uint index)
362 { 362 {
363 uint fmt (wchar* dst, uint length, inout Error e) 363 uint fmt (wchar* dst, uint length, inout UErrorCode e)
364 { 364 {
365 return uregex_group (handle, index, dst, length, e); 365 return uregex_group (handle, index, dst, length, e);
366 } 366 }
367 367
368 s.format (&fmt, "failed to extract regex group text"); 368 s.format (&fmt, "failed to extract regex group text");
375 375
376 ***********************************************************************/ 376 ***********************************************************************/
377 377
378 uint groupCount () 378 uint groupCount ()
379 { 379 {
380 Error e; 380 UErrorCode e;
381 381
382 uint i = uregex_groupCount (handle, e); 382 uint i = uregex_groupCount (handle, e);
383 testError (e, "failed to get regex group-count"); 383 testError (e, "failed to get regex group-count");
384 return i; 384 return i;
385 } 385 }
397 397
398 ***********************************************************************/ 398 ***********************************************************************/
399 399
400 uint start (uint index = 0) 400 uint start (uint index = 0)
401 { 401 {
402 Error e; 402 UErrorCode e;
403 403
404 uint i = uregex_start (handle, index, e); 404 uint i = uregex_start (handle, index, e);
405 testError (e, "failed to get regex start"); 405 testError (e, "failed to get regex start");
406 return i; 406 return i;
407 } 407 }
419 419
420 ***********************************************************************/ 420 ***********************************************************************/
421 421
422 uint end (uint index = 0) 422 uint end (uint index = 0)
423 { 423 {
424 Error e; 424 UErrorCode e;
425 425
426 uint i = uregex_end (handle, index, e); 426 uint i = uregex_end (handle, index, e);
427 testError (e, "failed to get regex end"); 427 testError (e, "failed to get regex end");
428 return i; 428 return i;
429 } 429 }
439 439
440 ***********************************************************************/ 440 ***********************************************************************/
441 441
442 void reset (uint startIndex) 442 void reset (uint startIndex)
443 { 443 {
444 Error e; 444 UErrorCode e;
445 445
446 uregex_reset (handle, startIndex, e); 446 uregex_reset (handle, startIndex, e);
447 testError (e, "failed to set regex next-index"); 447 testError (e, "failed to set regex next-index");
448 } 448 }
449 449
457 457
458 ***********************************************************************/ 458 ***********************************************************************/
459 459
460 bool match (uint startIndex) 460 bool match (uint startIndex)
461 { 461 {
462 Error e; 462 UErrorCode e;
463 463
464 bool b = uregex_matches (handle, startIndex, e); 464 bool b = uregex_matches (handle, startIndex, e);
465 testError (e, "failed while matching regex"); 465 testError (e, "failed while matching regex");
466 return b; 466 return b;
467 } 467 }
476 476
477 ***********************************************************************/ 477 ***********************************************************************/
478 478
479 bool probe (uint startIndex) 479 bool probe (uint startIndex)
480 { 480 {
481 Error e; 481 UErrorCode e;
482 482
483 bool b = uregex_lookingAt (handle, startIndex, e); 483 bool b = uregex_lookingAt (handle, startIndex, e);
484 testError (e, "failed while looking at regex"); 484 testError (e, "failed while looking at regex");
485 return b; 485 return b;
486 } 486 }
495 495
496 ***********************************************************************/ 496 ***********************************************************************/
497 497
498 bool next (uint startIndex = uint.max) 498 bool next (uint startIndex = uint.max)
499 { 499 {
500 Error e; 500 UErrorCode e;
501 bool b; 501 bool b;
502 502
503 b = (startIndex == uint.max) ? uregex_findNext (handle, e) : 503 b = (startIndex == uint.max) ? uregex_findNext (handle, e) :
504 uregex_find (handle, startIndex, e); 504 uregex_find (handle, startIndex, e);
505 505
533 longer than the length of 'result'. If it is longer, then 533 longer than the length of 'result'. If it is longer, then
534 the result has been truncated. 534 the result has been truncated.
535 535
536 ***********************************************************************/ 536 ***********************************************************************/
537 537
538 uint replaceAll (UText replace, UString result) 538 uint replaceAll (UStringView replace, UString result)
539 { 539 {
540 Error e; 540 UErrorCode e;
541 541
542 uint len = uregex_replaceAll (handle, replace.get.ptr, replace.length, result.get.ptr, result.length, e); 542 uint len = uregex_replaceAll (handle, replace.get.ptr, replace.length, result.get.ptr, result.length, e);
543 testError (e, "failed during regex replace"); 543 testError (e, "failed during regex replace");
544 result.truncate (len); 544 result.truncate (len);
545 return len; 545 return len;
571 longer than the length of 'result'. If it is longer, then 571 longer than the length of 'result'. If it is longer, then
572 the result has been truncated. 572 the result has been truncated.
573 573
574 ***********************************************************************/ 574 ***********************************************************************/
575 575
576 uint replaceFirst (UText replace, UString result) 576 uint replaceFirst (UStringView replace, UString result)
577 { 577 {
578 Error e; 578 UErrorCode e;
579 579
580 uint len = uregex_replaceFirst (handle, replace.get.ptr, replace.length, result.get.ptr, result.length, e); 580 uint len = uregex_replaceFirst (handle, replace.get.ptr, replace.length, result.get.ptr, result.length, e);
581 testError (e, "failed during regex replace"); 581 testError (e, "failed during regex replace");
582 result.truncate (len); 582 result.truncate (len);
583 return len; 583 return len;
592 592
593 ***********************************************************************/ 593 ***********************************************************************/
594 594
595 uint split (wchar[][] fields) 595 uint split (wchar[][] fields)
596 { 596 {
597 Error e; 597 UErrorCode e;
598 uint pos, 598 uint pos,
599 count; 599 count;
600 wchar[] content = theText.get; 600 wchar[] content = theText.get;
601 601
602 while (count < fields.length) 602 while (count < fields.length)
632 632
633 ***********************************************************************/ 633 ***********************************************************************/
634 634
635 private static extern (C) 635 private static extern (C)
636 { 636 {
637 Handle function (wchar*, uint, uint, ParseError*, inout Error) uregex_open; 637 Handle function (wchar*, uint, uint, ParseError*, inout UErrorCode) uregex_open;
638 void function (Handle) uregex_close; 638 void function (Handle) uregex_close;
639 Handle function (Handle, inout Error) uregex_clone; 639 Handle function (Handle, inout UErrorCode) uregex_clone;
640 wchar* function (Handle, inout uint, inout Error) uregex_pattern; 640 wchar* function (Handle, inout uint, inout UErrorCode) uregex_pattern;
641 uint function (Handle, inout Error) uregex_flags; 641 uint function (Handle, inout UErrorCode) uregex_flags;
642 void function (Handle, wchar*, uint, inout Error) uregex_setText; 642 void function (Handle, wchar*, uint, inout UErrorCode) uregex_setText;
643 wchar* function (Handle, inout uint, inout Error) uregex_getText; 643 wchar* function (Handle, inout uint, inout UErrorCode) uregex_getText;
644 uint function (Handle, uint, wchar*, uint, inout Error) uregex_group; 644 uint function (Handle, uint, wchar*, uint, inout UErrorCode) uregex_group;
645 uint function (Handle, inout Error) uregex_groupCount; 645 uint function (Handle, inout UErrorCode) uregex_groupCount;
646 uint function (Handle, uint, inout Error) uregex_start; 646 uint function (Handle, uint, inout UErrorCode) uregex_start;
647 uint function (Handle, uint, inout Error) uregex_end; 647 uint function (Handle, uint, inout UErrorCode) uregex_end;
648 void function (Handle, uint, inout Error) uregex_reset; 648 void function (Handle, uint, inout UErrorCode) uregex_reset;
649 bool function (Handle, uint, inout Error) uregex_matches; 649 bool function (Handle, uint, inout UErrorCode) uregex_matches;
650 bool function (Handle, uint, inout Error) uregex_lookingAt; 650 bool function (Handle, uint, inout UErrorCode) uregex_lookingAt;
651 bool function (Handle, uint, inout Error) uregex_find; 651 bool function (Handle, uint, inout UErrorCode) uregex_find;
652 bool function (Handle, inout Error) uregex_findNext; 652 bool function (Handle, inout UErrorCode) uregex_findNext;
653 uint function (Handle, wchar*, uint, wchar*, uint, inout Error) uregex_replaceAll; 653 uint function (Handle, wchar*, uint, wchar*, uint, inout UErrorCode) uregex_replaceAll;
654 uint function (Handle, wchar*, uint, wchar*, uint, inout Error) uregex_replaceFirst; 654 uint function (Handle, wchar*, uint, wchar*, uint, inout UErrorCode) uregex_replaceFirst;
655 } 655 }
656 656
657 /*********************************************************************** 657 /***********************************************************************
658 658
659 ***********************************************************************/ 659 ***********************************************************************/