Changeset 212:ab60f3309436 for dwt/dwthelper/utils.d
- Timestamp:
- 05/04/08 18:12:38 (8 months ago)
- Files:
-
- dwt/dwthelper/utils.d (modified) (50 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
dwt/dwthelper/utils.d
r206 r212 36 36 alias tango.text.Text.Text!(char) StringBuffer; 37 37 38 void implMissing( char[]file, uint line ){38 void implMissing( String file, uint line ){ 39 39 Stderr.formatln( "implementation missing in file {} line {}", file, line ); 40 40 Stderr.formatln( "exiting ..." ); … … 95 95 return value; 96 96 } 97 public static Boolean valueOf( char[]s ){97 public static Boolean valueOf( String s ){ 98 98 if( s == "yes" || s == "true" ){ 99 99 return TRUE; … … 110 110 111 111 class Byte : ValueWrapperT!(byte) { 112 public static byte parseByte( char[]s ){112 public static byte parseByte( String s ){ 113 113 try{ 114 114 int res = tango.text.convert.Integer.parse( s ); … … 139 139 } 140 140 141 public this ( char[]s ){141 public this ( String s ){ 142 142 super(parseInt(s)); 143 143 } 144 144 145 public static char[]toString( int i, int radix ){145 public static String toString( int i, int radix ){ 146 146 switch( radix ){ 147 147 case 2: … … 159 159 } 160 160 161 public static char[]toHexString( int i ){161 public static String toHexString( int i ){ 162 162 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Hex ); 163 163 } 164 164 165 public static char[]toOctalString( int i ){165 public static String toOctalString( int i ){ 166 166 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Octal ); 167 167 } 168 168 169 public static char[]toBinaryString( int i ){169 public static String toBinaryString( int i ){ 170 170 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Binary ); 171 171 } 172 172 173 public static char[]toString( int i ){173 public static String toString( int i ){ 174 174 return tango.text.convert.Integer.toString(i); 175 175 } 176 176 177 public static int parseInt( char[]s, int radix ){177 public static int parseInt( String s, int radix ){ 178 178 try{ 179 179 return tango.text.convert.Integer.parse( s, cast(uint)radix ); … … 184 184 } 185 185 186 public static int parseInt( char[]s ){186 public static int parseInt( String s ){ 187 187 try{ 188 188 return tango.text.convert.Integer.parse( s ); … … 193 193 } 194 194 195 public static Integer valueOf( char[]s, int radix ){195 public static Integer valueOf( String s, int radix ){ 196 196 implMissing( __FILE__, __LINE__ ); 197 197 return null; 198 198 } 199 199 200 public static Integer valueOf( char[]s ){200 public static Integer valueOf( String s ){ 201 201 return valueOf( parseInt(s)); 202 202 } … … 234 234 } 235 235 236 public override char[]toString(){236 public override String toString(){ 237 237 return tango.text.convert.Integer.toString( value ); 238 238 } … … 244 244 super(value); 245 245 } 246 this( char[]str ){246 this( String str ){ 247 247 implMissing( __FILE__, __LINE__ ); 248 248 super(0.0); … … 251 251 return value; 252 252 } 253 public static char[]toString( double value ){253 public static String toString( double value ){ 254 254 implMissing( __FILE__, __LINE__ ); 255 255 return null; … … 269 269 super(value); 270 270 } 271 this( char[]str ){271 this( String str ){ 272 272 implMissing( __FILE__, __LINE__ ); 273 273 super(0.0); … … 276 276 return value; 277 277 } 278 public static char[]toString( float value ){278 public static String toString( float value ){ 279 279 implMissing( __FILE__, __LINE__ ); 280 280 return null; 281 281 } 282 public static float parseFloat( char[]s ){282 public static float parseFloat( String s ){ 283 283 try{ 284 284 return tango.text.convert.Float.toFloat( s ); … … 294 294 super(value); 295 295 } 296 this( char[]str ){296 this( String str ){ 297 297 implMissing( __FILE__, __LINE__ ); 298 298 super(0); … … 301 301 return value; 302 302 } 303 public static long parseLong( char[]s){303 public static long parseLong(String s){ 304 304 implMissing( __FILE__, __LINE__ ); 305 305 return 0; 306 306 } 307 public static char[]toString( double value ){307 public static String toString( double value ){ 308 308 implMissing( __FILE__, __LINE__ ); 309 309 return null; … … 319 319 alias ArrayWrapperT!(Object) ArrayWrapperObject; 320 320 alias ArrayWrapperT!(char) ArrayWrapperString; 321 alias ArrayWrapperT!( char[]) ArrayWrapperString2;321 alias ArrayWrapperT!(String) ArrayWrapperString2; 322 322 323 323 Object[] StringArrayToObjectArray( String[] strs ){ … … 328 328 return res; 329 329 } 330 int codepointIndexToIndex( char[]str, int cpIndex ){330 int codepointIndexToIndex( String str, int cpIndex ){ 331 331 int cps = cpIndex; 332 332 int res = 0; … … 348 348 return res; 349 349 } 350 int indexToCodepointIndex( char[]str, int index ){350 int indexToCodepointIndex( String str, int index ){ 351 351 int i = 0; 352 352 int res = 0; … … 369 369 } 370 370 371 char[] firstCodePointStr( char[]str, out int consumed ){371 String firstCodePointStr( String str, out int consumed ){ 372 372 dchar[1] buf; 373 373 uint ate; … … 377 377 } 378 378 379 dchar firstCodePoint( char[]str ){379 dchar firstCodePoint( String str ){ 380 380 int dummy; 381 381 return firstCodePoint( str, dummy ); 382 382 } 383 dchar firstCodePoint( char[]str, out int consumed ){383 dchar firstCodePoint( String str, out int consumed ){ 384 384 dchar[1] buf; 385 385 uint ate; … … 394 394 } 395 395 396 char[]dcharToString( dchar key ){396 String dcharToString( dchar key ){ 397 397 dchar[1] buf; 398 398 buf[0] = key; … … 400 400 } 401 401 402 int codepointCount( char[]str ){402 int codepointCount( String str ){ 403 403 scope dchar[] buf = new dchar[]( str.length ); 404 404 uint ate; … … 411 411 alias tango.text.convert.Utf.toString toString; 412 412 413 int getRelativeCodePointOffset( char[]str, int startIndex, int searchRelCp ){413 int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ 414 414 int ignore; 415 415 int i = startIndex; … … 463 463 return i - startIndex; 464 464 } 465 dchar getRelativeCodePoint( char[]str, int startIndex, int searchRelCp, out int relIndex ){465 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ 466 466 relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); 467 467 int ignore; … … 469 469 } 470 470 471 int utf8AdjustOffset( char[]str, int offset ){471 int utf8AdjustOffset( String str, int offset ){ 472 472 if( str.length <= offset || offset <= 0 ){ 473 473 return offset; … … 482 482 return (ch in tango.text.UnicodeData.unicodeData) !is null; 483 483 } 484 dchar CharacterFirstToLower( char[]str ){484 dchar CharacterFirstToLower( String str ){ 485 485 int consumed; 486 486 return CharacterFirstToLower( str, consumed ); 487 487 } 488 dchar CharacterFirstToLower( char[]str, out int consumed ){488 dchar CharacterFirstToLower( String str, out int consumed ){ 489 489 dchar[1] buf; 490 490 buf[0] = firstCodePoint( str, consumed ); … … 510 510 return tango.text.Unicode.isLetter( c ); 511 511 } 512 public char[] toUpperCase( char[]str ){512 public String toUpperCase( String str ){ 513 513 return tango.text.Unicode.toUpper( str ); 514 514 } 515 515 516 public int indexOf( char[]str, char searched ){516 public int indexOf( String str, char searched ){ 517 517 int res = tango.text.Util.locate( str, searched ); 518 518 if( res is str.length ) res = -1; … … 520 520 } 521 521 522 public int indexOf( char[]str, char searched, int startpos ){522 public int indexOf( String str, char searched, int startpos ){ 523 523 int res = tango.text.Util.locate( str, searched, startpos ); 524 524 if( res is str.length ) res = -1; … … 526 526 } 527 527 528 public int indexOf( char[] str, char[]ch){528 public int indexOf(String str, String ch){ 529 529 return indexOf( str, ch, 0 ); 530 530 } 531 531 532 public int indexOf( char[] str, char[]ch, int start){532 public int indexOf(String str, String ch, int start){ 533 533 int res = tango.text.Util.locatePattern( str, ch, start ); 534 534 if( res is str.length ) res = -1; … … 536 536 } 537 537 538 public int lastIndexOf( char[]str, char ch){538 public int lastIndexOf(String str, char ch){ 539 539 return lastIndexOf( str, ch, str.length ); 540 540 } 541 public int lastIndexOf( char[]str, char ch, int formIndex){541 public int lastIndexOf(String str, char ch, int formIndex){ 542 542 int res = tango.text.Util.locatePrior( str, ch, formIndex ); 543 543 if( res is str.length ) res = -1; 544 544 return res; 545 545 } 546 public int lastIndexOf( char[] str, char[]ch ){546 public int lastIndexOf(String str, String ch ){ 547 547 return lastIndexOf( str, ch, str.length ); 548 548 } 549 public int lastIndexOf( char[] str, char[]ch, int start ){549 public int lastIndexOf(String str, String ch, int start ){ 550 550 int res = tango.text.Util.locatePatternPrior( str, ch, start ); 551 551 if( res is str.length ) res = -1; … … 553 553 } 554 554 555 public char[] replace( char[]str, char from, char to ){555 public String replace( String str, char from, char to ){ 556 556 return tango.text.Util.replace( str.dup, from, to ); 557 557 } 558 558 559 public char[] substring( char[]str, int start ){559 public String substring( String str, int start ){ 560 560 return str[ start .. $ ].dup; 561 561 } 562 562 563 public char[] substring( char[]str, int start, int end ){563 public String substring( String str, int start, int end ){ 564 564 return str[ start .. end ].dup; 565 565 } … … 573 573 } 574 574 575 public char charAt( char[]str, int pos ){575 public char charAt( String str, int pos ){ 576 576 return str[ pos ]; 577 577 } 578 578 579 public void getChars( char[] src, int srcBegin, int srcEnd, char[]dst, int dstBegin){579 public void getChars( String src, int srcBegin, int srcEnd, String dst, int dstBegin){ 580 580 dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; 581 581 } 582 582 583 public wchar[] toCharArray( char[]str ){583 public wchar[] toCharArray( String str ){ 584 584 return toString16( str ); 585 585 } 586 586 587 public bool endsWith( char[] src, char[]pattern ){587 public bool endsWith( String src, String pattern ){ 588 588 if( src.length < pattern.length ){ 589 589 return false; … … 592 592 } 593 593 594 public bool equals( char[] src, char[]other ){594 public bool equals( String src, String other ){ 595 595 return src == other; 596 596 } 597 597 598 public bool equalsIgnoreCase( char[] src, char[]other ){598 public bool equalsIgnoreCase( String src, String other ){ 599 599 return tango.text.Unicode.toFold(src) == tango.text.Unicode.toFold(other); 600 600 } 601 601 602 public bool startsWith( char[] src, char[]pattern ){602 public bool startsWith( String src, String pattern ){ 603 603 if( src.length < pattern.length ){ 604 604 return false; … … 607 607 } 608 608 609 public char[] toLowerCase( char[]src ){609 public String toLowerCase( String src ){ 610 610 return tango.text.Unicode.toLower( src ); 611 611 } 612 612 613 public hash_t toHash( char[]src ){614 return typeid( char[]).getHash(&src);615 } 616 617 public char[] trim( char[]str ){613 public hash_t toHash( String src ){ 614 return typeid(String).getHash(&src); 615 } 616 617 public String trim( String str ){ 618 618 return tango.text.Util.trim( str ).dup; 619 619 } 620 public char[] intern( char[]str ){620 public String intern( String str ){ 621 621 return str; 622 622 } 623 623 624 public char* toStringzValidPtr( char[]src ){624 public char* toStringzValidPtr( String src ){ 625 625 if( src ){ 626 626 return src.toStringz(); 627 627 } 628 628 else{ 629 static const char[]nullPtr = "\0";629 static const String nullPtr = "\0"; 630 630 return nullPtr.ptr; 631 631 } 632 632 } 633 633 634 static char[]toHex(uint value, bool prefix = true, int radix = 8){634 static String toHex(uint value, bool prefix = true, int radix = 8){ 635 635 return tango.text.convert.Integer.toString( 636 636 value, … … 644 644 645 645 class RuntimeException : Exception { 646 this( char[]e = null){646 this( String e = null){ 647 647 super(e); 648 648 } … … 657 657 } 658 658 class IndexOutOfBoundsException : Exception { 659 this( char[]e = null){659 this( String e = null){ 660 660 super(e); 661 661 } … … 663 663 664 664 class UnsupportedOperationException : RuntimeException { 665 this( char[]e = null){665 this( String e = null){ 666 666 super(e); 667 667 } … … 671 671 } 672 672 class NumberFormatException : IllegalArgumentException { 673 this( char[]e ){673 this( String e ){ 674 674 super(e); 675 675 } … … 679 679 } 680 680 class NullPointerException : Exception { 681 this( char[]e = null ){681 this( String e = null ){ 682 682 super(e); 683 683 } … … 687 687 } 688 688 class IllegalStateException : Exception { 689 this( char[]e = null ){689 this( String e = null ){ 690 690 super(e); 691 691 } … … 695 695 } 696 696 class InterruptedException : Exception { 697 this( char[]e = null ){697 this( String e = null ){ 698 698 super(e); 699 699 } … … 704 704 class InvocationTargetException : Exception { 705 705 Exception cause; 706 this( Exception e = null, char[]msg = null ){706 this( Exception e = null, String msg = null ){ 707 707 super(msg); 708 708 cause = e; … … 715 715 } 716 716 class MissingResourceException : Exception { 717 char[]classname;718 char[]key;719 this( char[] msg, char[] classname, char[]key ){717 String classname; 718 String key; 719 this( String msg, String classname, String key ){ 720 720 super(msg); 721 721 this.classname = classname; … … 724 724 } 725 725 class ParseException : Exception { 726 this( char[]e = null ){726 this( String e = null ){ 727 727 super(e); 728 728 } … … 754 754 } 755 755 756 public override char[]toString() {756 public override String toString() { 757 757 return this.classinfo.name ~ "[source=" ~ source.toString() ~ "]"; 758 758 } … … 832 832 } 833 833 834 char[]stringcast( Object o ){834 String stringcast( Object o ){ 835 835 if( auto str = cast(ArrayWrapperString) o ){ 836 836 return str.array; … … 838 838 return null; 839 839 } 840 char[][] stringcast( Object[] objs ){841 char[][] res = new char[][](objs.length);840 String[] stringcast( Object[] objs ){ 841 String[] res = new String[](objs.length); 842 842 foreach( idx, obj; objs ){ 843 843 res[idx] = stringcast(obj); … … 845 845 return res; 846 846 } 847 ArrayWrapperString stringcast( char[]str ){847 ArrayWrapperString stringcast( String str ){ 848 848 return new ArrayWrapperString( str ); 849 849 } 850 ArrayWrapperString[] stringcast( char[][] strs ){850 ArrayWrapperString[] stringcast( String[] strs ){ 851 851 ArrayWrapperString[] res = new ArrayWrapperString[ strs.length ]; 852 852 foreach( idx, str; strs ){ … … 937 937 } 938 938 939 void PrintStackTrace( int deepth = 100, char[]prefix = "trc" ){939 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ 940 940 auto e = new Exception( null ); 941 941 int idx = 0; … … 951 951 struct ImportData{ 952 952 void[] data; 953 char[]name;954 955 public static ImportData opCall( void[] data, char[]name ){953 String name; 954 955 public static ImportData opCall( void[] data, String name ){ 956 956 ImportData res; 957 957 res.data = data; … … 961 961 } 962 962 963 template getImportData( char[]name ){963 template getImportData(String name ){ 964 964 const ImportData getImportData = ImportData( import(name), name ); 965 965 }
