Mercurial > projects > dwt2
comparison base/src/java/lang/String.d @ 112:9f4c18c268b2
Update to compile and execute with dmd 2.052.
author | kntroh |
---|---|
date | Wed, 16 Mar 2011 21:53:53 +0900 |
parents | 9e0ab372d5d8 |
children | fb3aa8075988 |
comparison
equal
deleted
inserted
replaced
111:b6e9904989ed | 112:9f4c18c268b2 |
---|---|
12 static import tango.text.convert.Utf; | 12 static import tango.text.convert.Utf; |
13 } else { // Phobos | 13 } else { // Phobos |
14 static import core.exception; | 14 static import core.exception; |
15 static import std.uni; | 15 static import std.uni; |
16 static import std.utf; | 16 static import std.utf; |
17 static import std.array; | |
17 static import std.string; | 18 static import std.string; |
19 static import std.conv; | |
20 static import std.exception; | |
18 } | 21 } |
19 | 22 |
20 version(Tango){ | 23 version(Tango){ |
21 public alias char[] String; | 24 public alias char[] String; |
22 public alias char[] CString; | 25 public alias char[] CString; |
29 } else { // Phobos | 32 } else { // Phobos |
30 public alias string String; | 33 public alias string String; |
31 public alias wstring String16; | 34 public alias wstring String16; |
32 mixin("public alias const(char)[] CString;"); | 35 mixin("public alias const(char)[] CString;"); |
33 mixin("public alias const(wchar)[] CString16;"); | 36 mixin("public alias const(wchar)[] CString16;"); |
34 mixin("public alias invariant(char)* ICharPtr;"); | 37 mixin("public alias immutable(char)* ICharPtr;"); |
35 mixin("public alias const(char)* CCharPtr;"); | 38 mixin("public alias const(char)* CCharPtr;"); |
36 mixin("public alias const(wchar)* CWCharPtr;"); | 39 mixin("public alias const(wchar)* CWCharPtr;"); |
37 mixin("public alias invariant(wchar)* IWCharPtr;"); | 40 mixin("public alias immutable(wchar)* IWCharPtr;"); |
38 } | 41 } |
39 | 42 |
40 int codepointIndexToIndex( CString str, int cpIndex ){ | 43 int codepointIndexToIndex( CString str, int cpIndex ){ |
41 int cps = cpIndex; | 44 int cps = cpIndex; |
42 int res = 0; | 45 int res = 0; |
400 | 403 |
401 String String_valueOf( int v ){ | 404 String String_valueOf( int v ){ |
402 version(Tango){ | 405 version(Tango){ |
403 return tango.text.convert.Integer.toString(v); | 406 return tango.text.convert.Integer.toString(v); |
404 } else { // Phobos | 407 } else { // Phobos |
405 implMissing( __FILE__, __LINE__ ); | 408 return std.conv.to!(String)(v); |
406 return null; | |
407 } | 409 } |
408 } | 410 } |
409 | 411 |
410 String String_valueOf( uint v ){ | 412 String String_valueOf( uint v ){ |
411 version(Tango){ | 413 version(Tango){ |
412 return tango.text.convert.Integer.toString(v); | 414 return tango.text.convert.Integer.toString(v); |
413 } else { // Phobos | 415 } else { // Phobos |
414 implMissing( __FILE__, __LINE__ ); | 416 return std.conv.to!(String)(v); |
415 return null; | |
416 } | 417 } |
417 } | 418 } |
418 | 419 |
419 String String_valueOf( long v ){ | 420 String String_valueOf( long v ){ |
420 version(Tango){ | 421 version(Tango){ |
421 return tango.text.convert.Integer.toString(v); | 422 return tango.text.convert.Integer.toString(v); |
422 } else { // Phobos | 423 } else { // Phobos |
423 implMissing( __FILE__, __LINE__ ); | 424 return std.conv.to!(String)(v); |
424 return null; | |
425 } | 425 } |
426 } | 426 } |
427 | 427 |
428 String String_valueOf( float v ){ | 428 String String_valueOf( float v ){ |
429 version(Tango){ | 429 version(Tango){ |
430 return tango.text.convert.Float.toString(v); | 430 return tango.text.convert.Float.toString(v); |
431 } else { // Phobos | 431 } else { // Phobos |
432 implMissing( __FILE__, __LINE__ ); | 432 return std.conv.to!(String)(v); |
433 return null; | |
434 } | 433 } |
435 } | 434 } |
436 | 435 |
437 String String_valueOf( double v ){ | 436 String String_valueOf( double v ){ |
438 version(Tango){ | 437 version(Tango){ |
439 return tango.text.convert.Float.toString(v); | 438 return tango.text.convert.Float.toString(v); |
440 } else { // Phobos | 439 } else { // Phobos |
441 implMissing( __FILE__, __LINE__ ); | 440 return std.conv.to!(String)(v); |
442 return null; | |
443 } | 441 } |
444 } | 442 } |
445 | 443 |
446 String String_valueOf( dchar v ){ | 444 String String_valueOf( dchar v ){ |
447 return dcharToString(v); | 445 return dcharToString(v); |
469 | 467 |
470 String String_valueOf( CString16 wstr ){ | 468 String String_valueOf( CString16 wstr ){ |
471 version(Tango){ | 469 version(Tango){ |
472 return tango.text.convert.Utf.toString(wstr); | 470 return tango.text.convert.Utf.toString(wstr); |
473 } else { // Phobos | 471 } else { // Phobos |
474 implMissing( __FILE__, __LINE__ ); | 472 return std.conv.to!(String)(wstr); |
475 return null; | |
476 } | 473 } |
477 } | 474 } |
478 | 475 |
479 int length( CString str ){ | 476 int length( CString str ){ |
480 return str.length; | 477 return str.length; |
501 version(Tango){ | 498 version(Tango){ |
502 int res = tango.text.Util.locate( str, searched ); | 499 int res = tango.text.Util.locate( str, searched ); |
503 if( res is str.length ) res = -1; | 500 if( res is str.length ) res = -1; |
504 return res; | 501 return res; |
505 } else { // Phobos | 502 } else { // Phobos |
506 implMissing( __FILE__, __LINE__ ); | 503 return std.string.indexOf(str, searched); |
507 return 0; | |
508 } | 504 } |
509 } | 505 } |
510 | 506 |
511 /// Extension to String | 507 /// Extension to String |
512 public int indexOf( CString str, char searched, int startpos ){ | 508 public int indexOf( CString str, char searched, int startpos ){ |
513 version(Tango){ | 509 version(Tango){ |
514 int res = tango.text.Util.locate( str, searched, startpos ); | 510 int res = tango.text.Util.locate( str, searched, startpos ); |
515 if( res is str.length ) res = -1; | 511 if( res is str.length ) res = -1; |
516 return res; | 512 return res; |
517 } else { // Phobos | 513 } else { // Phobos |
518 implMissing( __FILE__, __LINE__ ); | 514 int res = std.string.indexOf(str[startpos .. $], searched); |
519 return 0; | 515 if (res !is -1) res += startpos; |
516 return res; | |
520 } | 517 } |
521 } | 518 } |
522 | 519 |
523 /// Extension to String | 520 /// Extension to String |
524 public int indexOf(CString str, String ch){ | 521 public int indexOf(CString str, String ch){ |
580 /// Extension to String | 577 /// Extension to String |
581 public String replace( CString str, char from, char to ){ | 578 public String replace( CString str, char from, char to ){ |
582 version(Tango){ | 579 version(Tango){ |
583 return tango.text.Util.replace( str.dup, from, to ); | 580 return tango.text.Util.replace( str.dup, from, to ); |
584 } else { // Phobos | 581 } else { // Phobos |
585 implMissing( __FILE__, __LINE__ ); | 582 auto res = std.array.replace(str, [from], [to]); |
586 return null; | 583 return std.exception.assumeUnique(res); |
587 } | 584 } |
588 } | 585 } |
589 | 586 |
590 /// Extension to String | 587 /// Extension to String |
591 public String substring( CString str, int start ){ | 588 public String substring( CString str, int start ){ |
625 /// Extension to String | 622 /// Extension to String |
626 public String16 toWCharArray( CString str ){ | 623 public String16 toWCharArray( CString str ){ |
627 version(Tango){ | 624 version(Tango){ |
628 return tango.text.convert.Utf.toString16(str); | 625 return tango.text.convert.Utf.toString16(str); |
629 } else { // Phobos | 626 } else { // Phobos |
630 implMissing( __FILE__, __LINE__ ); | 627 return std.conv.to!(String16)(str); |
631 return null; | |
632 } | 628 } |
633 } | 629 } |
634 | 630 |
635 /// Extension to String | 631 /// Extension to String |
636 public char[] toCharArray( CString str ){ | 632 public char[] toCharArray( CString str ){ |