Mercurial > projects > dwt2
comparison base/src/java/lang/String.d @ 39:0ecb2b338560
further work on phobosification
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Wed, 25 Mar 2009 13:20:43 +0100 |
parents | 1bf55a6eb092 |
children | d5075f5226e5 |
comparison
equal
deleted
inserted
replaced
38:2e09b0e6857a | 39:0ecb2b338560 |
---|---|
17 } | 17 } |
18 | 18 |
19 version(Tango){ | 19 version(Tango){ |
20 alias char[] String; | 20 alias char[] String; |
21 alias char[] CString; | 21 alias char[] CString; |
22 alias wchar[] String16; | |
22 alias wchar[] CString16; | 23 alias wchar[] CString16; |
23 } else { // Phobos | 24 } else { // Phobos |
24 alias string String; | 25 alias string String; |
25 alias wstring String16; | 26 alias wstring String16; |
26 mixin("alias const(char)[] CString;"); | 27 mixin("alias const(char)[] CString;"); |
96 + Get first codepoint of a String. If an offset is needed, simply use a slice: | 97 + Get first codepoint of a String. If an offset is needed, simply use a slice: |
97 + --- | 98 + --- |
98 + dchar res = str[ offset .. $ ].firstCodePoint(); | 99 + dchar res = str[ offset .. $ ].firstCodePoint(); |
99 + --- | 100 + --- |
100 +/ | 101 +/ |
101 dchar firstCodePoint( String str ){ | 102 dchar firstCodePoint( CString str ){ |
102 int dummy; | 103 int dummy; |
103 return firstCodePoint( str, dummy ); | 104 return firstCodePoint( str, dummy ); |
104 } | 105 } |
105 dchar firstCodePoint( String str, out int consumed ){ | 106 dchar firstCodePoint( CString str, out int consumed ){ |
106 version(Tango){ | 107 version(Tango){ |
107 dchar[1] buf; | 108 dchar[1] buf; |
108 uint ate; | 109 uint ate; |
109 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); | 110 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); |
110 consumed = ate; | 111 consumed = ate; |
117 } else { // Phobos | 118 } else { // Phobos |
118 implMissing( __FILE__, __LINE__ ); | 119 implMissing( __FILE__, __LINE__ ); |
119 return '\0'; | 120 return '\0'; |
120 } | 121 } |
121 } | 122 } |
122 dchar firstCodePoint( wchar[] str, out int consumed ){ | 123 dchar firstCodePoint( CString16 str, out int consumed ){ |
123 version(Tango){ | 124 version(Tango){ |
124 dchar[1] buf; | 125 dchar[1] buf; |
125 uint ate; | 126 uint ate; |
126 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); | 127 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); |
127 consumed = ate; | 128 consumed = ate; |
254 searchRelCp++; | 255 searchRelCp++; |
255 } | 256 } |
256 } | 257 } |
257 return i; | 258 return i; |
258 } | 259 } |
259 int getAbsoluteCodePointOffset( wchar[] str, int startIndex, int searchRelCp ){ | 260 int getAbsoluteCodePointOffset( CString16 str, int startIndex, int searchRelCp ){ |
260 int ignore; | 261 int ignore; |
261 int i = startIndex; | 262 int i = startIndex; |
262 if( searchRelCp > 0 ){ | 263 if( searchRelCp > 0 ){ |
263 while( searchRelCp !is 0 ){ | 264 while( searchRelCp !is 0 ){ |
264 | 265 |
455 | 456 |
456 String String_valueOf( Object v ){ | 457 String String_valueOf( Object v ){ |
457 return v is null ? "null" : v.toString(); | 458 return v is null ? "null" : v.toString(); |
458 } | 459 } |
459 | 460 |
460 String String_valueOf( wchar[] wstr ){ | 461 String String_valueOf( CString16 wstr ){ |
461 version(Tango){ | 462 version(Tango){ |
462 return tango.text.convert.Utf.toString(wstr); | 463 return tango.text.convert.Utf.toString(wstr); |
463 } else { // Phobos | 464 } else { // Phobos |
464 implMissing( __FILE__, __LINE__ ); | 465 implMissing( __FILE__, __LINE__ ); |
465 return null; | 466 return null; |
469 int length( String str ){ | 470 int length( String str ){ |
470 return str.length; | 471 return str.length; |
471 } | 472 } |
472 | 473 |
473 /// Extension to String | 474 /// Extension to String |
474 public String toUpperCase( String str ){ | 475 public String toUpperCase( CString str ){ |
475 version(Tango){ | 476 version(Tango){ |
476 return tango.text.Unicode.toUpper( str ); | 477 return tango.text.Unicode.toUpper( str ); |
477 } else { // Phobos | 478 } else { // Phobos |
478 implMissing( __FILE__, __LINE__ ); | 479 implMissing( __FILE__, __LINE__ ); |
479 return null; | 480 return null; |
480 } | 481 } |
481 } | 482 } |
482 | 483 |
483 /// Extension to String | 484 /// Extension to String |
484 public String replaceFirst( String str, String regex, String replacement ){ | 485 public String replaceFirst( CString str, CString regex, CString replacement ){ |
485 implMissing(__FILE__,__LINE__); | 486 implMissing(__FILE__,__LINE__); |
486 return str; | 487 return null; |
487 } | 488 } |
488 | 489 |
489 /// Extension to String | 490 /// Extension to String |
490 public int indexOf( String str, char searched ){ | 491 public int indexOf( CString str, char searched ){ |
491 version(Tango){ | 492 version(Tango){ |
492 int res = tango.text.Util.locate( str, searched ); | 493 int res = tango.text.Util.locate( str, searched ); |
493 if( res is str.length ) res = -1; | 494 if( res is str.length ) res = -1; |
494 return res; | 495 return res; |
495 } else { // Phobos | 496 } else { // Phobos |
497 return 0; | 498 return 0; |
498 } | 499 } |
499 } | 500 } |
500 | 501 |
501 /// Extension to String | 502 /// Extension to String |
502 public int indexOf( String str, char searched, int startpos ){ | 503 public int indexOf( CString str, char searched, int startpos ){ |
503 version(Tango){ | 504 version(Tango){ |
504 int res = tango.text.Util.locate( str, searched, startpos ); | 505 int res = tango.text.Util.locate( str, searched, startpos ); |
505 if( res is str.length ) res = -1; | 506 if( res is str.length ) res = -1; |
506 return res; | 507 return res; |
507 } else { // Phobos | 508 } else { // Phobos |
509 return 0; | 510 return 0; |
510 } | 511 } |
511 } | 512 } |
512 | 513 |
513 /// Extension to String | 514 /// Extension to String |
514 public int indexOf(String str, String ch){ | 515 public int indexOf(CString str, String ch){ |
515 return indexOf( str, ch, 0 ); | 516 return indexOf( str, ch, 0 ); |
516 } | 517 } |
517 | 518 |
518 /// Extension to String | 519 /// Extension to String |
519 public int indexOf(String str, String ch, int start){ | 520 public int indexOf(CString str, String ch, int start){ |
520 version(Tango){ | 521 version(Tango){ |
521 int res = tango.text.Util.locatePattern( str, ch, start ); | 522 int res = tango.text.Util.locatePattern( str, ch, start ); |
522 if( res is str.length ) res = -1; | 523 if( res is str.length ) res = -1; |
523 return res; | 524 return res; |
524 } else { // Phobos | 525 } else { // Phobos |
526 return 0; | 527 return 0; |
527 } | 528 } |
528 } | 529 } |
529 | 530 |
530 /// Extension to String | 531 /// Extension to String |
531 public int lastIndexOf(String str, char ch){ | 532 public int lastIndexOf(CString str, char ch){ |
532 return lastIndexOf( str, ch, str.length ); | 533 return lastIndexOf( str, ch, str.length ); |
533 } | 534 } |
534 | 535 |
535 /// Extension to String | 536 /// Extension to String |
536 public int lastIndexOf(String str, char ch, int formIndex){ | 537 public int lastIndexOf(CString str, char ch, int formIndex){ |
537 version(Tango){ | 538 version(Tango){ |
538 int res = tango.text.Util.locatePrior( str, ch, formIndex ); | 539 int res = tango.text.Util.locatePrior( str, ch, formIndex ); |
539 if( res is str.length ) res = -1; | 540 if( res is str.length ) res = -1; |
540 return res; | 541 return res; |
541 } else { // Phobos | 542 } else { // Phobos |
543 return 0; | 544 return 0; |
544 } | 545 } |
545 } | 546 } |
546 | 547 |
547 /// Extension to String | 548 /// Extension to String |
548 public int lastIndexOf(String str, String ch ){ | 549 public int lastIndexOf(CString str, String ch ){ |
549 return lastIndexOf( str, ch, str.length ); | 550 return lastIndexOf( str, ch, str.length ); |
550 } | 551 } |
551 | 552 |
552 /// Extension to String | 553 /// Extension to String |
553 public int lastIndexOf(String str, String ch, int start ){ | 554 public int lastIndexOf(CString str, String ch, int start ){ |
554 version(Tango){ | 555 version(Tango){ |
555 int res = tango.text.Util.locatePatternPrior( str, ch, start ); | 556 int res = tango.text.Util.locatePatternPrior( str, ch, start ); |
556 if( res is str.length ) res = -1; | 557 if( res is str.length ) res = -1; |
557 return res; | 558 return res; |
558 } else { // Phobos | 559 } else { // Phobos |
560 return 0; | 561 return 0; |
561 } | 562 } |
562 } | 563 } |
563 | 564 |
564 /// Extension to String | 565 /// Extension to String |
565 public String replaceAll( String str, String regex, String replacement ){ | 566 public String replaceAll( CString str, String regex, String replacement ){ |
566 implMissing(__FILE__,__LINE__); | 567 implMissing(__FILE__,__LINE__); |
567 return null; | 568 return null; |
568 } | 569 } |
569 | 570 |
570 /// Extension to String | 571 /// Extension to String |
571 public String replace( String str, char from, char to ){ | 572 public String replace( CString str, char from, char to ){ |
572 version(Tango){ | 573 version(Tango){ |
573 return tango.text.Util.replace( str.dup, from, to ); | 574 return tango.text.Util.replace( str.dup, from, to ); |
574 } else { // Phobos | 575 } else { // Phobos |
575 implMissing( __FILE__, __LINE__ ); | 576 implMissing( __FILE__, __LINE__ ); |
576 return null; | 577 return null; |
577 } | 578 } |
578 } | 579 } |
579 | 580 |
580 /// Extension to String | 581 /// Extension to String |
581 public String substring( String str, int start ){ | 582 public String substring( CString str, int start ){ |
582 return cast(String)str[ start .. $ ].dup; | 583 return cast(String)str[ start .. $ ].dup; |
583 } | 584 } |
584 | 585 |
585 /// Extension to String | 586 /// Extension to String |
586 public String substring( String str, int start, int end ){ | 587 public String substring( CString str, int start, int end ){ |
587 return cast(String)str[ start .. end ].dup; | 588 return cast(String)str[ start .. end ].dup; |
588 } | 589 } |
589 | 590 |
590 /// Extension to String | 591 /// Extension to String |
591 public wchar[] substring( wchar[] str, int start ){ | 592 public wchar[] substring( CString16 str, int start ){ |
592 return cast(wchar[])(str[ start .. $ ].dup); | 593 return cast(wchar[])(str[ start .. $ ].dup); |
593 } | 594 } |
594 | 595 |
595 /// Extension to String | 596 /// Extension to String |
596 public wchar[] substring( wchar[] str, int start, int end ){ | 597 public wchar[] substring( CString16 str, int start, int end ){ |
597 return str[ start .. end ].dup; | 598 return str[ start .. end ].dup; |
598 } | 599 } |
599 | 600 |
600 /// Extension to String | 601 /// Extension to String |
601 public char charAt( String str, int pos ){ | 602 public char charAt( CString str, int pos ){ |
602 return str[ pos ]; | 603 return str[ pos ]; |
603 } | 604 } |
604 | 605 |
605 /// Extension to String | 606 /// Extension to String |
606 public dchar dcharAt( String str, int pos ){ | 607 public dchar dcharAt( CString str, int pos ){ |
607 return str[ pos .. $ ].firstCodePoint(); | 608 return str[ pos .. $ ].firstCodePoint(); |
608 } | 609 } |
609 | 610 |
610 /// Extension to String | 611 /// Extension to String |
611 public void getChars( String src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ | 612 public void getChars( String src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
612 dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; | 613 dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; |
613 } | 614 } |
614 | 615 |
615 /// Extension to String | 616 /// Extension to String |
616 public wchar[] toWCharArray( String str ){ | 617 public String16 toWCharArray( CString str ){ |
617 version(Tango){ | 618 version(Tango){ |
618 return tango.text.convert.Utf.toString16(str); | 619 return tango.text.convert.Utf.toString16(str); |
619 } else { // Phobos | 620 } else { // Phobos |
620 implMissing( __FILE__, __LINE__ ); | 621 implMissing( __FILE__, __LINE__ ); |
621 return null; | 622 return null; |