comparison base/src/java/lang/String.d @ 51:c01d033c633a

[swt lin]
author Frank Benoit <benoit@tionex.de>
date Fri, 27 Mar 2009 19:58:06 +0100
parents d5075f5226e5
children 70388b0e6dad
comparison
equal deleted inserted replaced
50:d5075f5226e5 51:c01d033c633a
34 mixin("alias const(char*) CCharPtr;"); 34 mixin("alias const(char*) CCharPtr;");
35 mixin("alias const(wchar*) CWCharPtr;"); 35 mixin("alias const(wchar*) CWCharPtr;");
36 mixin("alias invariant(wchar*) IWCharPtr;"); 36 mixin("alias invariant(wchar*) IWCharPtr;");
37 } 37 }
38 38
39 int codepointIndexToIndex( String str, int cpIndex ){ 39 int codepointIndexToIndex( CString str, int cpIndex ){
40 int cps = cpIndex; 40 int cps = cpIndex;
41 int res = 0; 41 int res = 0;
42 while( cps > 0 ){ 42 while( cps > 0 ){
43 cps--; 43 cps--;
44 if( str[res] < 0x80 ){ 44 if( str[res] < 0x80 ){
58 } 58 }
59 59
60 /++ 60 /++
61 + 61 +
62 +/ 62 +/
63 int indexToCodepointIndex( String str, int index ){ 63 int indexToCodepointIndex( CString str, int index ){
64 if( index < 0 ) return index; 64 if( index < 0 ) return index;
65 int i = 0; 65 int i = 0;
66 int res = 0; 66 int res = 0;
67 while( i < index ){ 67 while( i < index ){
68 if( i >= str.length ){ 68 if( i >= str.length ){
86 } 86 }
87 87
88 /++ 88 /++
89 + Get that String, that contains the next codepoint of a String. 89 + Get that String, that contains the next codepoint of a String.
90 +/ 90 +/
91 String firstCodePointStr( String str, out int consumed ){ 91 String firstCodePointStr( CString str, out int consumed ){
92 version(Tango){ 92 version(Tango){
93 dchar[1] buf; 93 dchar[1] buf;
94 uint ate; 94 uint ate;
95 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); 95 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate );
96 consumed = ate; 96 consumed = ate;
155 implMissing( __FILE__, __LINE__ ); 155 implMissing( __FILE__, __LINE__ );
156 return null; 156 return null;
157 } 157 }
158 } 158 }
159 159
160 int codepointCount( String str ){ 160 int codepointCount( CString str ){
161 version(Tango){ 161 version(Tango){
162 scope dchar[] buf = new dchar[]( str.length ); 162 scope dchar[] buf = new dchar[]( str.length );
163 uint ate; 163 uint ate;
164 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); 164 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate );
165 assert( ate is str.length ); 165 assert( ate is str.length );
171 } 171 }
172 172
173 //alias tango.text.convert.Utf.toString16 toString16; 173 //alias tango.text.convert.Utf.toString16 toString16;
174 //alias tango.text.convert.Utf.toString toString; 174 //alias tango.text.convert.Utf.toString toString;
175 175
176 int toAbsoluteCodePointStartOffset( String str, int index ){ 176 int toAbsoluteCodePointStartOffset( CString str, int index ){
177 //getDwtLogger().trace( __FILE__, __LINE__, "str={}, str.length={}, index={}", str, str.length, index ); 177 //getDwtLogger().trace( __FILE__, __LINE__, "str={}, str.length={}, index={}", str, str.length, index );
178 //getDwtLogger().trace( __FILE__, __LINE__, Trace.memory( str ); 178 //getDwtLogger().trace( __FILE__, __LINE__, Trace.memory( str );
179 if( str.length is index ){ 179 if( str.length is index ){
180 return index; 180 return index;
181 } 181 }
204 throw new UnicodeException( "invalid utf8 input to toAbsoluteCodePointStartOffset", index ); 204 throw new UnicodeException( "invalid utf8 input to toAbsoluteCodePointStartOffset", index );
205 } 205 }
206 return index; 206 return index;
207 } 207 }
208 } 208 }
209 int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ 209 int getRelativeCodePointOffset( CString str, int startIndex, int searchRelCp ){
210 return getAbsoluteCodePointOffset( str, startIndex, searchRelCp ) - startIndex; 210 return getAbsoluteCodePointOffset( str, startIndex, searchRelCp ) - startIndex;
211 } 211 }
212 int getAbsoluteCodePointOffset( String str, int startIndex, int searchRelCp ){ 212 int getAbsoluteCodePointOffset( CString str, int startIndex, int searchRelCp ){
213 213
214 //getDwtLogger().trace( __FILE__, __LINE__, "str={}, str.length={}, startIndex={}, searchRelCp={}", str, str.length, startIndex, searchRelCp ); 214 //getDwtLogger().trace( __FILE__, __LINE__, "str={}, str.length={}, startIndex={}, searchRelCp={}", str, str.length, startIndex, searchRelCp );
215 //getDwtLogger().trace( __FILE__, __LINE__, Trace.memory( str ); 215 //getDwtLogger().trace( __FILE__, __LINE__, Trace.memory( str );
216 216
217 int ignore; 217 int ignore;
714 714
715 /++ 715 /++
716 + This is like tango.stdc.stringz.toStringz, but in case of an empty input string, 716 + This is like tango.stdc.stringz.toStringz, but in case of an empty input string,
717 + this function returns a pointer to a null value instead of a null ptr. 717 + this function returns a pointer to a null value instead of a null ptr.
718 +/ 718 +/
719 public char* toStringzValidPtr( String src ){ 719 public char* toStringzValidPtr( CString src ){
720 if( src ){ 720 if( src ){
721 return src.toStringz(); 721 return src.toStringz();
722 } 722 }
723 else{ 723 else{
724 static const char[] nullPtr = "\0"; 724 static const char[] nullPtr = "\0";