Mercurial > projects > dwt-linux
annotate dwt/dwthelper/utils.d @ 262:e10de397beb1
ADD version TANGOSVN
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 06 Jul 2008 15:33:12 +0200 |
parents | 5a30aa9820f3 |
children | d472fae79005 |
rev | line source |
---|---|
12 | 1 /** |
2 * Authors: Frank Benoit <keinfarbton@googlemail.com> | |
3 */ | |
4 module dwt.dwthelper.utils; | |
5 | |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
12
diff
changeset
|
6 public import dwt.dwthelper.System; |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
7 public import Math = tango.math.Math; |
25
fc2b263b8a3f
Merged back the System.arraycopy and use a System class
Frank Benoit <benoit@tionex.de>
parents:
12
diff
changeset
|
8 |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
9 public import tango.core.Exception : IllegalArgumentException, IOException; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
10 |
12 | 11 import tango.io.Stdout; |
219 | 12 import tango.io.Print; |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
13 static import tango.stdc.stringz; |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
14 static import tango.text.Util; |
219 | 15 static import tango.text.Text; |
109 | 16 import tango.text.Unicode; |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
17 import tango.text.convert.Utf; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
18 import tango.core.Exception; |
12 | 19 import tango.stdc.stdlib : exit; |
20 | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
21 import tango.util.log.Trace; |
219 | 22 import tango.text.UnicodeData; |
23 static import tango.util.collection.model.Seq; | |
24 | |
25 alias char[] String; | |
26 alias tango.text.Text.Text!(char) StringBuffer; | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
27 |
238 | 28 void implMissing( String file, uint line ){ |
12 | 29 Stderr.formatln( "implementation missing in file {} line {}", file, line ); |
30 Stderr.formatln( "exiting ..." ); | |
31 exit(1); | |
32 } | |
33 | |
26 | 34 abstract class ArrayWrapper{ |
35 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
36 abstract class ValueWrapper{ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
37 } |
26 | 38 |
39 class ArrayWrapperT(T) : ArrayWrapper { | |
27 | 40 public T[] array; |
41 public this( T[] data ){ | |
42 array = data; | |
43 } | |
26 | 44 } |
45 | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
46 class ValueWrapperT(T) : ValueWrapper { |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
47 public T value; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
48 public this( T data ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
49 value = data; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
50 } |
219 | 51 public int opEquals( T other ){ |
52 return value == other; | |
53 } | |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
54 public int opEquals( Object other ){ |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
55 if( auto o = cast(ValueWrapperT!(T))other ){ |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
56 return value == o.value; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
57 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
58 return false; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
59 } |
219 | 60 } |
61 | |
62 class Boolean : ValueWrapperT!(bool) { | |
63 public static Boolean TRUE; | |
64 public static Boolean FALSE; | |
226 | 65 |
66 static this(){ | |
67 TRUE = new Boolean(true); | |
68 FALSE = new Boolean(false); | |
69 } | |
219 | 70 public this( bool v ){ |
71 super(v); | |
72 } | |
73 | |
74 alias ValueWrapperT!(bool).opEquals opEquals; | |
75 public int opEquals( int other ){ | |
76 return value == ( other !is 0 ); | |
77 } | |
78 public int opEquals( Object other ){ | |
79 if( auto o = cast(Boolean)other ){ | |
80 return value == o.value; | |
81 } | |
82 return false; | |
83 } | |
84 public bool booleanValue(){ | |
85 return value; | |
86 } | |
238 | 87 public static Boolean valueOf( String s ){ |
227 | 88 if( s == "yes" || s == "true" ){ |
89 return TRUE; | |
90 } | |
91 return FALSE; | |
92 } | |
93 public static Boolean valueOf( bool b ){ | |
94 return b ? TRUE : FALSE; | |
95 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
96 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
97 |
219 | 98 alias Boolean ValueWrapperBool; |
99 | |
100 | |
101 class Byte : ValueWrapperT!(byte) { | |
238 | 102 public static byte parseByte( String s ){ |
219 | 103 try{ |
104 int res = tango.text.convert.Integer.parse( s ); | |
105 if( res < byte.min || res > byte.max ){ | |
106 throw new NumberFormatException( "out of range" ); | |
107 } | |
108 return res; | |
109 } | |
110 catch( IllegalArgumentException e ){ | |
111 throw new NumberFormatException( e ); | |
112 } | |
113 } | |
114 this( byte value ){ | |
115 super( value ); | |
116 } | |
117 } | |
118 alias Byte ValueWrapperByte; | |
119 | |
120 | |
121 class Integer : ValueWrapperT!(int) { | |
122 | |
250 | 123 public static const int MIN_VALUE = 0x80000000; |
124 public static const int MAX_VALUE = 0x7fffffff; | |
125 public static const int SIZE = 32; | |
219 | 126 |
127 public this ( int value ){ | |
128 super( value ); | |
129 } | |
130 | |
238 | 131 public this ( String s ){ |
226 | 132 super(parseInt(s)); |
219 | 133 } |
134 | |
238 | 135 public static String toString( int i, int radix ){ |
219 | 136 switch( radix ){ |
137 case 2: | |
138 return toBinaryString(i); | |
139 case 8: | |
140 return toOctalString(i); | |
141 case 10: | |
142 return toString(i); | |
143 case 16: | |
144 return toHexString(i); | |
145 default: | |
146 implMissing( __FILE__, __LINE__ ); | |
147 return null; | |
148 } | |
149 } | |
150 | |
238 | 151 public static String toHexString( int i ){ |
262 | 152 version(TANGOSVN) |
153 return tango.text.convert.Integer.toString(i, "x" ); | |
154 } | |
155 else{ | |
219 | 156 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Hex ); |
262 | 157 } |
219 | 158 } |
159 | |
238 | 160 public static String toOctalString( int i ){ |
262 | 161 version(TANGOSVN) |
162 return tango.text.convert.Integer.toString(i, "o" ); | |
163 } | |
164 else{ | |
219 | 165 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Octal ); |
262 | 166 } |
219 | 167 } |
168 | |
238 | 169 public static String toBinaryString( int i ){ |
262 | 170 version(TANGOSVN) |
171 return tango.text.convert.Integer.toString(i, "b" ); | |
172 } | |
173 else{ | |
219 | 174 return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Binary ); |
262 | 175 } |
219 | 176 } |
177 | |
238 | 178 public static String toString( int i ){ |
219 | 179 return tango.text.convert.Integer.toString(i); |
180 } | |
181 | |
238 | 182 public static int parseInt( String s, int radix ){ |
219 | 183 try{ |
184 return tango.text.convert.Integer.parse( s, cast(uint)radix ); | |
185 } | |
186 catch( IllegalArgumentException e ){ | |
187 throw new NumberFormatException( e ); | |
188 } | |
189 } | |
190 | |
238 | 191 public static int parseInt( String s ){ |
219 | 192 try{ |
193 return tango.text.convert.Integer.parse( s ); | |
194 } | |
195 catch( IllegalArgumentException e ){ | |
196 throw new NumberFormatException( e ); | |
197 } | |
198 } | |
199 | |
238 | 200 public static Integer valueOf( String s, int radix ){ |
219 | 201 implMissing( __FILE__, __LINE__ ); |
202 return null; | |
203 } | |
204 | |
238 | 205 public static Integer valueOf( String s ){ |
226 | 206 return valueOf( parseInt(s)); |
219 | 207 } |
208 | |
209 public static Integer valueOf( int i ){ | |
226 | 210 return new Integer(i); |
219 | 211 } |
212 | |
213 public byte byteValue(){ | |
214 return cast(byte)value; | |
215 } | |
216 | |
217 public short shortValue(){ | |
218 return cast(short)value; | |
219 } | |
220 | |
221 public int intValue(){ | |
222 return value; | |
223 } | |
224 | |
225 public long longValue(){ | |
226 return cast(long)value; | |
227 } | |
228 | |
229 public float floatValue(){ | |
230 return cast(float)value; | |
231 } | |
232 | |
233 public double doubleValue(){ | |
234 return cast(double)value; | |
235 } | |
236 | |
237 public override hash_t toHash(){ | |
238 return intValue(); | |
239 } | |
240 | |
238 | 241 public override String toString(){ |
219 | 242 return tango.text.convert.Integer.toString( value ); |
243 } | |
244 } | |
245 alias Integer ValueWrapperInt; | |
246 | |
247 class Double : ValueWrapperT!(double) { | |
248 this( double value ){ | |
249 super(value); | |
250 } | |
238 | 251 this( String str ){ |
219 | 252 implMissing( __FILE__, __LINE__ ); |
253 super(0.0); | |
254 } | |
255 public double doubleValue(){ | |
256 return value; | |
257 } | |
238 | 258 public static String toString( double value ){ |
219 | 259 implMissing( __FILE__, __LINE__ ); |
260 return null; | |
261 } | |
262 } | |
263 | |
264 class Float : ValueWrapperT!(float) { | |
228 | 265 |
266 public static float POSITIVE_INFINITY = (1.0f / 0.0f); | |
267 public static float NEGATIVE_INFINITY = ((-1.0f) / 0.0f); | |
268 public static float NaN = (0.0f / 0.0f); | |
269 public static float MAX_VALUE = 3.4028235e+38f; | |
270 public static float MIN_VALUE = 1.4e-45f; | |
271 public static int SIZE = 32; | |
272 | |
219 | 273 this( float value ){ |
274 super(value); | |
275 } | |
238 | 276 this( String str ){ |
219 | 277 implMissing( __FILE__, __LINE__ ); |
278 super(0.0); | |
279 } | |
280 public float floatValue(){ | |
281 return value; | |
282 } | |
238 | 283 public static String toString( float value ){ |
219 | 284 implMissing( __FILE__, __LINE__ ); |
285 return null; | |
286 } | |
238 | 287 public static float parseFloat( String s ){ |
228 | 288 try{ |
289 return tango.text.convert.Float.toFloat( s ); | |
290 } | |
291 catch( IllegalArgumentException e ){ | |
292 throw new NumberFormatException( e ); | |
293 } | |
294 } | |
295 | |
219 | 296 } |
297 class Long : ValueWrapperT!(long) { | |
298 this( long value ){ | |
299 super(value); | |
300 } | |
238 | 301 this( String str ){ |
219 | 302 implMissing( __FILE__, __LINE__ ); |
303 super(0); | |
304 } | |
305 public long longValue(){ | |
306 return value; | |
307 } | |
238 | 308 public static long parseLong(String s){ |
219 | 309 implMissing( __FILE__, __LINE__ ); |
310 return 0; | |
311 } | |
238 | 312 public static String toString( double value ){ |
219 | 313 implMissing( __FILE__, __LINE__ ); |
314 return null; | |
315 } | |
316 } | |
317 alias Long ValueWrapperLong; | |
318 | |
319 | |
320 // alias ValueWrapperT!(int) ValueWrapperInt; | |
209 | 321 |
92 | 322 alias ArrayWrapperT!(byte) ArrayWrapperByte; |
323 alias ArrayWrapperT!(int) ArrayWrapperInt; | |
324 alias ArrayWrapperT!(Object) ArrayWrapperObject; | |
325 alias ArrayWrapperT!(char) ArrayWrapperString; | |
238 | 326 alias ArrayWrapperT!(String) ArrayWrapperString2; |
26 | 327 |
219 | 328 Object[] StringArrayToObjectArray( String[] strs ){ |
329 Object[] res = new Object[strs.length]; | |
330 foreach( idx, str; strs ){ | |
331 res[idx] = new ArrayWrapperString(str); | |
332 } | |
333 return res; | |
334 } | |
238 | 335 int codepointIndexToIndex( String str, int cpIndex ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
336 int cps = cpIndex; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
337 int res = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
338 while( cps > 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
339 cps--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
340 if( str[res] < 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
341 res+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
342 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
343 else if( str[res] < 0xE0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
344 res+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
345 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
346 else if( str[res] & 0xF0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
347 res+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
348 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
349 else{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
350 res+=4; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
351 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
352 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
353 return res; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
354 } |
238 | 355 int indexToCodepointIndex( String str, int index ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
356 int i = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
357 int res = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
358 while( i < index ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
359 if( str[i] < 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
360 i+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
361 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
362 else if( str[i] < 0xE0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
363 i+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
364 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
365 else if( str[i] & 0xF0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
366 i+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
367 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
368 else{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
369 i+=4; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
370 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
371 res++; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
372 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
373 return res; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
374 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
375 |
238 | 376 String firstCodePointStr( String str, out int consumed ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
377 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
378 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
379 dchar[] res = str.toString32( buf, &ate ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
380 consumed = ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
381 return str[ 0 .. ate ]; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
382 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
383 |
238 | 384 dchar firstCodePoint( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
385 int dummy; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
386 return firstCodePoint( str, dummy ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
387 } |
238 | 388 dchar firstCodePoint( String str, out int consumed ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
389 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
390 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
391 dchar[] res = str.toString32( buf, &ate ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
392 consumed = ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
393 if( ate is 0 || res.length is 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
394 Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
109 | 395 } |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
396 assert( ate > 0 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
397 assert( res.length is 1 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
398 return res[0]; |
103 | 399 } |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
400 |
238 | 401 String dcharToString( dchar key ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
402 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
403 buf[0] = key; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
404 return tango.text.convert.Utf.toString( buf ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
405 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
406 |
238 | 407 int codepointCount( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
408 scope dchar[] buf = new dchar[]( str.length ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
409 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
410 dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
411 assert( ate is str.length ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
412 return res.length; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
413 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
414 |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
415 alias tango.text.convert.Utf.toString16 toString16; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
416 alias tango.text.convert.Utf.toString toString; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
417 |
238 | 418 int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
419 int ignore; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
420 int i = startIndex; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
421 if( searchRelCp > 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
422 while( searchRelCp !is 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
423 |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
424 if( ( i < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
425 && ( str[i] & 0x80 ) is 0x00 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
426 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
427 i+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
428 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
429 else if( ( i+1 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
430 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
431 && (( str[i ] & 0xE0 ) is 0xC0 )) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
432 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
433 i+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
434 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
435 else if( ( i+2 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
436 && (( str[i+2] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
437 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
438 && (( str[i ] & 0xF0 ) is 0xE0 )) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
439 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
440 i+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
441 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
442 else if(( i+3 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
443 && (( str[i+3] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
444 && (( str[i+2] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
445 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
446 && (( str[i ] & 0xF8 ) is 0xF0 )) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
447 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
448 i+=4; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
449 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
450 else{ |
246
f08216d53777
Fix merge bug in TextLayout
Frank Benoit <benoit@tionex.de>
parents:
245
diff
changeset
|
451 Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); |
f08216d53777
Fix merge bug in TextLayout
Frank Benoit <benoit@tionex.de>
parents:
245
diff
changeset
|
452 tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
453 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
454 searchRelCp--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
455 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
456 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
457 else if( searchRelCp < 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
458 while( searchRelCp !is 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
459 do{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
460 i--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
461 if( i < 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
462 Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
463 tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
464 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
465 } while(( str[i] & 0xC0 ) is 0x80 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
466 searchRelCp++; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
467 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
468 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
469 return i - startIndex; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
470 } |
238 | 471 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
472 relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
473 int ignore; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
474 return firstCodePoint( str[ startIndex+relIndex .. $ ], ignore ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
475 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
476 |
238 | 477 int utf8AdjustOffset( String str, int offset ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
478 if( str.length <= offset || offset <= 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
479 return offset; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
480 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
481 while(( str[offset] & 0xC0 ) is 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
482 offset--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
483 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
484 return offset; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
485 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
486 |
219 | 487 bool CharacterIsDefined( dchar ch ){ |
488 return (ch in tango.text.UnicodeData.unicodeData) !is null; | |
489 } | |
238 | 490 dchar CharacterFirstToLower( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
491 int consumed; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
492 return CharacterFirstToLower( str, consumed ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
493 } |
238 | 494 dchar CharacterFirstToLower( String str, out int consumed ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
495 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
496 buf[0] = firstCodePoint( str, consumed ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
497 dchar[] r = tango.text.Unicode.toLower( buf ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
498 return r[0]; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
499 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
500 |
103 | 501 dchar CharacterToLower( dchar c ){ |
502 dchar[] r = tango.text.Unicode.toLower( [c] ); | |
503 return r[0]; | |
504 } | |
505 dchar CharacterToUpper( dchar c ){ | |
506 dchar[] r = tango.text.Unicode.toUpper( [c] ); | |
507 return r[0]; | |
508 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
509 bool CharacterIsWhitespace( dchar c ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
510 return tango.text.Unicode.isWhitespace( c ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
511 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
512 bool CharacterIsDigit( dchar c ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
513 return tango.text.Unicode.isDigit( c ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
514 } |
219 | 515 bool CharacterIsLetter( dchar c ){ |
516 return tango.text.Unicode.isLetter( c ); | |
517 } | |
238 | 518 public String toUpperCase( String str ){ |
219 | 519 return tango.text.Unicode.toUpper( str ); |
520 } | |
26 | 521 |
238 | 522 public int indexOf( String str, char searched ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
523 int res = tango.text.Util.locate( str, searched ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
524 if( res is str.length ) res = -1; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
525 return res; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
526 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
527 |
238 | 528 public int indexOf( String str, char searched, int startpos ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
529 int res = tango.text.Util.locate( str, searched, startpos ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
530 if( res is str.length ) res = -1; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
531 return res; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
532 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
533 |
238 | 534 public int indexOf(String str, String ch){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
535 return indexOf( str, ch, 0 ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
536 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
537 |
238 | 538 public int indexOf(String str, String ch, int start){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
539 int res = tango.text.Util.locatePattern( str, ch, start ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
540 if( res is str.length ) res = -1; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
541 return res; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
542 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
543 |
238 | 544 public int lastIndexOf(String str, char ch){ |
190 | 545 return lastIndexOf( str, ch, str.length ); |
546 } | |
238 | 547 public int lastIndexOf(String str, char ch, int formIndex){ |
190 | 548 int res = tango.text.Util.locatePrior( str, ch, formIndex ); |
549 if( res is str.length ) res = -1; | |
550 return res; | |
551 } | |
238 | 552 public int lastIndexOf(String str, String ch ){ |
219 | 553 return lastIndexOf( str, ch, str.length ); |
554 } | |
238 | 555 public int lastIndexOf(String str, String ch, int start ){ |
219 | 556 int res = tango.text.Util.locatePatternPrior( str, ch, start ); |
557 if( res is str.length ) res = -1; | |
558 return res; | |
559 } | |
190 | 560 |
238 | 561 public String replace( String str, char from, char to ){ |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
562 return tango.text.Util.replace( str.dup, from, to ); |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
563 } |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
564 |
238 | 565 public String substring( String str, int start ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
566 return str[ start .. $ ].dup; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
567 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
568 |
238 | 569 public String substring( String str, int start, int end ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
570 return str[ start .. end ].dup; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
571 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
572 |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
573 public wchar[] substring( wchar[] str, int start ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
574 return str[ start .. $ ].dup; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
575 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
576 |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
577 public wchar[] substring( wchar[] str, int start, int end ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
578 return str[ start .. end ].dup; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
579 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
580 |
238 | 581 public char charAt( String str, int pos ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
582 return str[ pos ]; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
583 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
584 |
238 | 585 public void getChars( String src, int srcBegin, int srcEnd, String dst, int dstBegin){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
586 dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
587 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
588 |
238 | 589 public wchar[] toCharArray( String str ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
590 return toString16( str ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
591 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
592 |
238 | 593 public bool endsWith( String src, String pattern ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
594 if( src.length < pattern.length ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
595 return false; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
596 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
597 return src[ $-pattern.length .. $ ] == pattern; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
598 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
599 |
238 | 600 public bool equals( String src, String other ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
601 return src == other; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
602 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
603 |
238 | 604 public bool equalsIgnoreCase( String src, String other ){ |
190 | 605 return tango.text.Unicode.toFold(src) == tango.text.Unicode.toFold(other); |
606 } | |
607 | |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
608 public int compareToIgnoreCase( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
609 return compareTo( tango.text.Unicode.toFold(src), tango.text.Unicode.toFold(other)); |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
610 } |
250 | 611 public int compareTo( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
612 return typeid(String).compare( cast(void*)&src, cast(void*)&other ); |
250 | 613 } |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
614 |
238 | 615 public bool startsWith( String src, String pattern ){ |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
616 if( src.length < pattern.length ){ |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
617 return false; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
618 } |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
619 return src[ 0 .. pattern.length ] == pattern; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
620 } |
210 | 621 |
238 | 622 public String toLowerCase( String src ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
623 return tango.text.Unicode.toLower( src ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
624 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
625 |
238 | 626 public hash_t toHash( String src ){ |
627 return typeid(String).getHash(&src); | |
191 | 628 } |
629 | |
238 | 630 public String trim( String str ){ |
210 | 631 return tango.text.Util.trim( str ).dup; |
632 } | |
238 | 633 public String intern( String str ){ |
219 | 634 return str; |
635 } | |
210 | 636 |
238 | 637 public char* toStringzValidPtr( String src ){ |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
638 if( src ){ |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
639 return src.toStringz(); |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
640 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
641 else{ |
238 | 642 static const String nullPtr = "\0"; |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
643 return nullPtr.ptr; |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
644 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
645 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
646 |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
647 public alias tango.stdc.stringz.toStringz toStringz; |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
648 public alias tango.stdc.stringz.toString16z toString16z; |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
649 public alias tango.stdc.stringz.fromStringz fromStringz; |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
650 public alias tango.stdc.stringz.fromString16z fromString16z; |
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
651 |
238 | 652 static String toHex(uint value, bool prefix = true, int radix = 8){ |
262 | 653 version(TANGOSVN) |
654 return tango.text.convert.Integer.toString( | |
655 value, | |
656 radix is 10 ? "d" : | |
657 radix is 8 ? "o" : | |
658 radix is 16 ? "x" : | |
659 "d" ); | |
660 } | |
661 else{ | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
662 return tango.text.convert.Integer.toString( |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
663 value, |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
664 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
665 radix is 8 ? tango.text.convert.Integer.Style.Octal : |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
666 radix is 16 ? tango.text.convert.Integer.Style.Hex : |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
667 tango.text.convert.Integer.Style.Signed, |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
668 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
669 ); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
670 } |
262 | 671 } |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
672 |
219 | 673 class RuntimeException : Exception { |
238 | 674 this( String e = null){ |
219 | 675 super(e); |
676 } | |
677 this( Exception e ){ | |
678 super(e.toString); | |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
679 next = e; |
219 | 680 } |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
681 public Exception getCause() { |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
682 return next; |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
683 } |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
684 |
219 | 685 } |
686 class IndexOutOfBoundsException : Exception { | |
238 | 687 this( String e = null){ |
219 | 688 super(e); |
689 } | |
690 } | |
691 | |
692 class UnsupportedOperationException : RuntimeException { | |
238 | 693 this( String e = null){ |
219 | 694 super(e); |
695 } | |
696 this( Exception e ){ | |
697 super(e.toString); | |
698 } | |
699 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
700 class NumberFormatException : IllegalArgumentException { |
238 | 701 this( String e ){ |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
702 super(e); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
703 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
704 this( Exception e ){ |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
705 super(e.toString); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
706 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
707 } |
219 | 708 class NullPointerException : Exception { |
238 | 709 this( String e = null ){ |
219 | 710 super(e); |
711 } | |
712 this( Exception e ){ | |
713 super(e.toString); | |
714 } | |
715 } | |
716 class IllegalStateException : Exception { | |
238 | 717 this( String e = null ){ |
219 | 718 super(e); |
719 } | |
720 this( Exception e ){ | |
721 super(e.toString); | |
722 } | |
723 } | |
724 class InterruptedException : Exception { | |
238 | 725 this( String e = null ){ |
219 | 726 super(e); |
727 } | |
728 this( Exception e ){ | |
729 super(e.toString); | |
730 } | |
731 } | |
732 class InvocationTargetException : Exception { | |
733 Exception cause; | |
238 | 734 this( Exception e = null, String msg = null ){ |
219 | 735 super(msg); |
736 cause = e; | |
737 } | |
738 | |
739 alias getCause getTargetException; | |
740 Exception getCause(){ | |
741 return cause; | |
742 } | |
743 } | |
744 class MissingResourceException : Exception { | |
238 | 745 String classname; |
746 String key; | |
747 this( String msg, String classname, String key ){ | |
219 | 748 super(msg); |
749 this.classname = classname; | |
750 this.key = key; | |
751 } | |
752 } | |
753 class ParseException : Exception { | |
238 | 754 this( String e = null ){ |
219 | 755 super(e); |
756 } | |
757 } | |
758 | |
759 interface Cloneable{ | |
760 } | |
761 | |
762 interface Comparable { | |
763 int compareTo(Object o); | |
764 } | |
765 interface Comparator { | |
766 int compare(Object o1, Object o2); | |
767 } | |
768 interface EventListener{ | |
769 } | |
770 | |
771 class EventObject { | |
772 protected Object source; | |
773 | |
774 public this(Object source) { | |
775 if (source is null) | |
776 throw new IllegalArgumentException( "null arg" ); | |
777 this.source = source; | |
778 } | |
779 | |
780 public Object getSource() { | |
781 return source; | |
782 } | |
783 | |
238 | 784 public override String toString() { |
219 | 785 return this.classinfo.name ~ "[source=" ~ source.toString() ~ "]"; |
786 } | |
787 } | |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
788 |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
789 private struct GCStats { |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
790 size_t poolsize; // total size of pool |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
791 size_t usedsize; // bytes allocated |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
792 size_t freeblocks; // number of blocks marked FREE |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
793 size_t freelistsize; // total of memory on free lists |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
794 size_t pageblocks; // number of blocks marked PAGE |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
795 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
796 private extern(C) GCStats gc_stats(); |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
797 |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
798 size_t RuntimeTotalMemory(){ |
228 | 799 GCStats s = gc_stats(); |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
800 return s.poolsize; |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
801 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
802 |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
803 String ExceptionGetLocalizedMessage( Exception e ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
804 return e.msg; |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
805 } |
158
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
806 |
219 | 807 void ExceptionPrintStackTrace( Exception e ){ |
808 ExceptionPrintStackTrace( e, Stderr ); | |
809 } | |
810 void ExceptionPrintStackTrace( Exception e, Print!(char) print ){ | |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
811 Exception exception = e; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
812 while( exception !is null ){ |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
813 print.formatln( "Exception in {}({}): {}", exception.file, exception.line, exception.msg ); |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
814 if( exception.info !is null ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
815 foreach( msg; exception.info ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
816 print.formatln( "trc {}", msg ); |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
817 } |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
818 } |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
819 exception = exception.next; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
820 } |
219 | 821 } |
822 | |
823 interface Reader{ | |
824 } | |
825 interface Writer{ | |
826 } | |
827 | |
828 | |
829 class Collator : Comparator { | |
830 public static Collator getInstance(){ | |
831 implMissing( __FILE__, __LINE__ ); | |
832 return null; | |
833 } | |
834 private this(){ | |
835 } | |
836 int compare(Object o1, Object o2){ | |
837 implMissing( __FILE__, __LINE__ ); | |
838 return 0; | |
839 } | |
840 } | |
841 | |
842 interface Enumeration { | |
843 public bool hasMoreElements(); | |
844 public Object nextElement(); | |
845 } | |
846 | |
847 | |
848 template arraycast(T) { | |
849 T[] arraycast(U) (U[] u) { | |
850 static if ( | |
851 (is (T == interface ) && is (U == interface )) || | |
852 (is (T == class ) && is (U == class ))) { | |
853 return(cast(T[])u); | |
854 } | |
855 else { | |
856 int l = u.length; | |
857 T[] res; | |
858 res.length = l; | |
859 for (int i = 0; i < l; i++) { | |
860 res[i] = cast(T)u[i]; | |
861 } | |
862 return(res); | |
863 } | |
864 } | |
865 } | |
866 | |
238 | 867 String stringcast( Object o ){ |
219 | 868 if( auto str = cast(ArrayWrapperString) o ){ |
869 return str.array; | |
870 } | |
871 return null; | |
872 } | |
238 | 873 String[] stringcast( Object[] objs ){ |
874 String[] res = new String[](objs.length); | |
219 | 875 foreach( idx, obj; objs ){ |
876 res[idx] = stringcast(obj); | |
877 } | |
878 return res; | |
879 } | |
238 | 880 ArrayWrapperString stringcast( String str ){ |
219 | 881 return new ArrayWrapperString( str ); |
882 } | |
238 | 883 ArrayWrapperString[] stringcast( String[] strs ){ |
219 | 884 ArrayWrapperString[] res = new ArrayWrapperString[ strs.length ]; |
885 foreach( idx, str; strs ){ | |
886 res[idx] = stringcast(str); | |
887 } | |
888 return res; | |
889 } | |
890 | |
891 | |
223 | 892 bool ArrayEquals(T)( T[] a, T[] b ){ |
893 if( a.length !is b.length ){ | |
894 return false; | |
895 } | |
896 for( int i = 0; i < a.length; i++ ){ | |
897 static if( is( T==class) || is(T==interface)){ | |
898 if( a[i] !is null && b[i] !is null ){ | |
899 if( a[i] != b[i] ){ | |
900 return false; | |
901 } | |
902 } | |
903 else if( a[i] is null && b[i] is null ){ | |
904 } | |
905 else{ | |
906 return false; | |
907 } | |
908 } | |
909 else{ | |
910 if( a[i] != b[i] ){ | |
911 return false; | |
912 } | |
913 } | |
914 } | |
226 | 915 return true; |
223 | 916 } |
917 | |
219 | 918 class Arrays{ |
919 public static bool equals(Object[] a, Object[] b){ | |
920 if( a.length !is b.length ){ | |
921 return false; | |
922 } | |
923 for( int i = 0; i < a.length; i++ ){ | |
924 if( a[i] is null && b[i] is null ){ | |
925 continue; | |
926 } | |
927 if( a[i] !is null && b[i] !is null && a[i] == b[i] ){ | |
928 continue; | |
929 } | |
930 return false; | |
931 } | |
932 return true; | |
933 } | |
934 } | |
935 | |
936 int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){ | |
937 int idx; | |
938 foreach( e; s ){ | |
939 if( e == src ){ | |
940 return idx; | |
941 } | |
942 idx++; | |
943 } | |
944 return -1; | |
945 } | |
946 int arrayIndexOf(T)( T[] arr, T v ){ | |
947 int res = -1; | |
948 int idx = 0; | |
949 foreach( p; arr ){ | |
950 if( p == v){ | |
951 res = idx; | |
952 break; | |
953 } | |
954 idx++; | |
955 } | |
956 return res; | |
957 } | |
958 | |
959 int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){ | |
960 int res = -1; | |
961 int idx = 0; | |
962 foreach( p; seq ){ | |
963 if( p == v){ | |
964 res = idx; | |
965 break; | |
966 } | |
967 idx++; | |
968 } | |
969 return res; | |
970 } | |
971 | |
238 | 972 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ |
229 | 973 auto e = new Exception( null ); |
974 int idx = 0; | |
975 const start = 3; | |
976 foreach( msg; e.info ){ | |
977 if( idx >= start && idx < start+deepth ) { | |
978 Trace.formatln( "{}: {}", prefix, msg ); | |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
979 } |
229 | 980 idx++; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
981 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
982 } |
219 | 983 |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
984 struct ImportData{ |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
985 void[] data; |
238 | 986 String name; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
987 |
238 | 988 public static ImportData opCall( void[] data, String name ){ |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
989 ImportData res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
990 res.data = data; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
991 res.name = name; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
992 return res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
993 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
994 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
995 |
238 | 996 template getImportData(String name ){ |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
997 const ImportData getImportData = ImportData( import(name), name ); |
238 | 998 } |