Mercurial > projects > dwt-linux
annotate dwt/dwthelper/utils.d @ 314:0f7ac29ac726
merge
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 01:35:33 +0200 |
parents | 9f01a0643e26 77fa7f3ab37e |
children | 6f57d3b9947c |
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; |
310
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
7 public import dwt.dwthelper.Runnable; |
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
|
8 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
|
9 |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
10 public import tango.core.Exception : IllegalArgumentException, IOException; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
11 |
12 | 12 import tango.io.Stdout; |
219 | 13 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
|
14 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
|
15 static import tango.text.Util; |
219 | 16 static import tango.text.Text; |
311 | 17 static import tango.text.Ascii; |
109 | 18 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
|
19 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
|
20 import tango.core.Exception; |
12 | 21 import tango.stdc.stdlib : exit; |
22 | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
23 import tango.util.log.Trace; |
219 | 24 import tango.text.UnicodeData; |
25 | |
26 alias char[] String; | |
27 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
|
28 |
311 | 29 alias ArrayBoundsException ArrayIndexOutOfBoundsException; |
30 | |
238 | 31 void implMissing( String file, uint line ){ |
12 | 32 Stderr.formatln( "implementation missing in file {} line {}", file, line ); |
33 Stderr.formatln( "exiting ..." ); | |
34 exit(1); | |
35 } | |
36 | |
26 | 37 abstract class ArrayWrapper{ |
38 } | |
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
|
39 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
|
40 } |
26 | 41 |
42 class ArrayWrapperT(T) : ArrayWrapper { | |
27 | 43 public T[] array; |
44 public this( T[] data ){ | |
45 array = data; | |
46 } | |
297
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
47 public override int opEquals( Object o ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
48 if( auto other = cast(ArrayWrapperT!(T))o){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
49 return array == other.array; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
50 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
51 return false; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
52 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
53 public override hash_t toHash(){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
54 return (typeid(T[])).getHash(&array); |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
55 } |
26 | 56 } |
57 | |
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
|
58 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
|
59 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
|
60 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
|
61 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
|
62 } |
297
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
63 static if( is(T==class) || is(T==interface)){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
64 public int opEquals( Object other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
65 if( auto o = cast(ValueWrapperT!(T))other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
66 return value == o.value; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
67 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
68 if( auto o = cast(T)other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
69 if( value is o ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
70 return true; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
71 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
72 if( value is null || o is null ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
73 return false; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
74 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
75 return value == o; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
76 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
77 return false; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
78 } |
219 | 79 } |
297
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
80 else{ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
81 public int opEquals( Object other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
82 if( auto o = cast(ValueWrapperT!(T))other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
83 return value == o.value; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
84 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
85 return false; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
86 } |
297
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
87 public int opEquals( T other ){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
88 return value == other; |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
89 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
90 } |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
91 public override hash_t toHash(){ |
2f204a4aebc6
Fix: missing opEquals, toHash for ArrayWrapper.
Frank Benoit <benoit@tionex.de>
parents:
292
diff
changeset
|
92 return (typeid(T)).getHash(&value); |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
93 } |
219 | 94 } |
95 | |
96 class Boolean : ValueWrapperT!(bool) { | |
97 public static Boolean TRUE; | |
98 public static Boolean FALSE; | |
226 | 99 |
100 static this(){ | |
101 TRUE = new Boolean(true); | |
102 FALSE = new Boolean(false); | |
103 } | |
219 | 104 public this( bool v ){ |
105 super(v); | |
106 } | |
107 | |
108 alias ValueWrapperT!(bool).opEquals opEquals; | |
109 public int opEquals( int other ){ | |
110 return value == ( other !is 0 ); | |
111 } | |
112 public int opEquals( Object other ){ | |
113 if( auto o = cast(Boolean)other ){ | |
114 return value == o.value; | |
115 } | |
116 return false; | |
117 } | |
118 public bool booleanValue(){ | |
119 return value; | |
120 } | |
238 | 121 public static Boolean valueOf( String s ){ |
227 | 122 if( s == "yes" || s == "true" ){ |
123 return TRUE; | |
124 } | |
125 return FALSE; | |
126 } | |
127 public static Boolean valueOf( bool b ){ | |
128 return b ? TRUE : FALSE; | |
129 } | |
311 | 130 public static bool getBoolean(String name){ |
131 return tango.text.Ascii.icompare(System.getProperty(name, "false"), "true" ) is 0; | |
132 } | |
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
|
133 } |
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
|
134 |
219 | 135 alias Boolean ValueWrapperBool; |
136 | |
137 | |
138 class Byte : ValueWrapperT!(byte) { | |
238 | 139 public static byte parseByte( String s ){ |
219 | 140 try{ |
141 int res = tango.text.convert.Integer.parse( s ); | |
142 if( res < byte.min || res > byte.max ){ | |
143 throw new NumberFormatException( "out of range" ); | |
144 } | |
145 return res; | |
146 } | |
147 catch( IllegalArgumentException e ){ | |
148 throw new NumberFormatException( e ); | |
149 } | |
150 } | |
151 this( byte value ){ | |
152 super( value ); | |
153 } | |
311 | 154 |
155 public static String toString( byte i ){ | |
156 return tango.text.convert.Integer.toString(i); | |
157 } | |
158 | |
219 | 159 } |
160 alias Byte ValueWrapperByte; | |
161 | |
162 | |
163 class Integer : ValueWrapperT!(int) { | |
164 | |
250 | 165 public static const int MIN_VALUE = 0x80000000; |
166 public static const int MAX_VALUE = 0x7fffffff; | |
167 public static const int SIZE = 32; | |
219 | 168 |
169 public this ( int value ){ | |
170 super( value ); | |
171 } | |
172 | |
238 | 173 public this ( String s ){ |
226 | 174 super(parseInt(s)); |
219 | 175 } |
176 | |
238 | 177 public static String toString( int i, int radix ){ |
219 | 178 switch( radix ){ |
179 case 2: | |
180 return toBinaryString(i); | |
181 case 8: | |
182 return toOctalString(i); | |
183 case 10: | |
184 return toString(i); | |
185 case 16: | |
186 return toHexString(i); | |
187 default: | |
188 implMissing( __FILE__, __LINE__ ); | |
189 return null; | |
190 } | |
191 } | |
192 | |
238 | 193 public static String toHexString( int i ){ |
262 | 194 return tango.text.convert.Integer.toString(i, "x" ); |
219 | 195 } |
196 | |
238 | 197 public static String toOctalString( int i ){ |
262 | 198 return tango.text.convert.Integer.toString(i, "o" ); |
219 | 199 } |
200 | |
238 | 201 public static String toBinaryString( int i ){ |
262 | 202 return tango.text.convert.Integer.toString(i, "b" ); |
219 | 203 } |
204 | |
238 | 205 public static String toString( int i ){ |
219 | 206 return tango.text.convert.Integer.toString(i); |
207 } | |
208 | |
238 | 209 public static int parseInt( String s, int radix ){ |
219 | 210 try{ |
307 | 211 return tango.text.convert.Integer.toLong( s, radix ); |
219 | 212 } |
213 catch( IllegalArgumentException e ){ | |
214 throw new NumberFormatException( e ); | |
215 } | |
216 } | |
217 | |
238 | 218 public static int parseInt( String s ){ |
219 | 219 try{ |
307 | 220 return tango.text.convert.Integer.toLong( s ); |
219 | 221 } |
222 catch( IllegalArgumentException e ){ | |
223 throw new NumberFormatException( e ); | |
224 } | |
225 } | |
226 | |
238 | 227 public static Integer valueOf( String s, int radix ){ |
219 | 228 implMissing( __FILE__, __LINE__ ); |
229 return null; | |
230 } | |
231 | |
238 | 232 public static Integer valueOf( String s ){ |
226 | 233 return valueOf( parseInt(s)); |
219 | 234 } |
235 | |
236 public static Integer valueOf( int i ){ | |
226 | 237 return new Integer(i); |
219 | 238 } |
239 | |
240 public byte byteValue(){ | |
241 return cast(byte)value; | |
242 } | |
243 | |
244 public short shortValue(){ | |
245 return cast(short)value; | |
246 } | |
247 | |
248 public int intValue(){ | |
249 return value; | |
250 } | |
251 | |
252 public long longValue(){ | |
253 return cast(long)value; | |
254 } | |
255 | |
256 public float floatValue(){ | |
257 return cast(float)value; | |
258 } | |
259 | |
260 public double doubleValue(){ | |
261 return cast(double)value; | |
262 } | |
263 | |
264 public override hash_t toHash(){ | |
265 return intValue(); | |
266 } | |
267 | |
238 | 268 public override String toString(){ |
219 | 269 return tango.text.convert.Integer.toString( value ); |
270 } | |
271 } | |
272 alias Integer ValueWrapperInt; | |
273 | |
274 class Double : ValueWrapperT!(double) { | |
283
05e48e1e65d1
Double constant values for Draw2D
Frank Benoit <benoit@tionex.de>
parents:
276
diff
changeset
|
275 public static double MAX_VALUE = double.max; |
05e48e1e65d1
Double constant values for Draw2D
Frank Benoit <benoit@tionex.de>
parents:
276
diff
changeset
|
276 public static double MIN_VALUE = double.min; |
219 | 277 this( double value ){ |
278 super(value); | |
279 } | |
238 | 280 this( String str ){ |
219 | 281 implMissing( __FILE__, __LINE__ ); |
282 super(0.0); | |
283 } | |
284 public double doubleValue(){ | |
285 return value; | |
286 } | |
238 | 287 public static String toString( double value ){ |
219 | 288 implMissing( __FILE__, __LINE__ ); |
289 return null; | |
290 } | |
311 | 291 public static double parseDouble(String s){ |
292 implMissing( __FILE__, __LINE__ ); | |
293 return 0.0; | |
294 } | |
219 | 295 } |
296 | |
297 class Float : ValueWrapperT!(float) { | |
228 | 298 |
299 public static float POSITIVE_INFINITY = (1.0f / 0.0f); | |
300 public static float NEGATIVE_INFINITY = ((-1.0f) / 0.0f); | |
301 public static float NaN = (0.0f / 0.0f); | |
302 public static float MAX_VALUE = 3.4028235e+38f; | |
303 public static float MIN_VALUE = 1.4e-45f; | |
304 public static int SIZE = 32; | |
305 | |
219 | 306 this( float value ){ |
307 super(value); | |
308 } | |
238 | 309 this( String str ){ |
219 | 310 implMissing( __FILE__, __LINE__ ); |
311 super(0.0); | |
312 } | |
313 public float floatValue(){ | |
314 return value; | |
315 } | |
238 | 316 public static String toString( float value ){ |
219 | 317 implMissing( __FILE__, __LINE__ ); |
318 return null; | |
319 } | |
238 | 320 public static float parseFloat( String s ){ |
228 | 321 try{ |
322 return tango.text.convert.Float.toFloat( s ); | |
323 } | |
324 catch( IllegalArgumentException e ){ | |
325 throw new NumberFormatException( e ); | |
326 } | |
327 } | |
328 | |
219 | 329 } |
330 class Long : ValueWrapperT!(long) { | |
300 | 331 public static const long MIN_VALUE = long.min; |
332 public static const long MAX_VALUE = long.max; | |
219 | 333 this( long value ){ |
334 super(value); | |
335 } | |
238 | 336 this( String str ){ |
219 | 337 implMissing( __FILE__, __LINE__ ); |
338 super(0); | |
339 } | |
340 public long longValue(){ | |
341 return value; | |
342 } | |
238 | 343 public static long parseLong(String s){ |
219 | 344 implMissing( __FILE__, __LINE__ ); |
345 return 0; | |
346 } | |
238 | 347 public static String toString( double value ){ |
219 | 348 implMissing( __FILE__, __LINE__ ); |
349 return null; | |
350 } | |
351 } | |
352 alias Long ValueWrapperLong; | |
353 | |
354 | |
355 // alias ValueWrapperT!(int) ValueWrapperInt; | |
209 | 356 |
92 | 357 alias ArrayWrapperT!(byte) ArrayWrapperByte; |
358 alias ArrayWrapperT!(int) ArrayWrapperInt; | |
359 alias ArrayWrapperT!(Object) ArrayWrapperObject; | |
360 alias ArrayWrapperT!(char) ArrayWrapperString; | |
238 | 361 alias ArrayWrapperT!(String) ArrayWrapperString2; |
26 | 362 |
219 | 363 Object[] StringArrayToObjectArray( String[] strs ){ |
364 Object[] res = new Object[strs.length]; | |
365 foreach( idx, str; strs ){ | |
366 res[idx] = new ArrayWrapperString(str); | |
367 } | |
368 return res; | |
369 } | |
238 | 370 int codepointIndexToIndex( String str, int cpIndex ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
371 int cps = cpIndex; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
372 int res = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
373 while( cps > 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
374 cps--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
375 if( str[res] < 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
376 res+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
377 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
378 else if( str[res] < 0xE0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
379 res+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
380 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
381 else if( str[res] & 0xF0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
382 res+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
383 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
384 else{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
385 res+=4; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
386 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
387 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
388 return res; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
389 } |
307 | 390 |
391 /++ | |
392 + | |
393 +/ | |
238 | 394 int indexToCodepointIndex( String str, int index ){ |
285
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
395 if( index < 0 ) return index; |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
396 int i = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
397 int res = 0; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
398 while( i < index ){ |
285
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
399 if( i >= str.length ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
400 break; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
401 } |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
402 if( str[i] < 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
403 i+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
404 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
405 else if( str[i] < 0xE0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
406 i+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
407 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
408 else if( str[i] & 0xF0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
409 i+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
410 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
411 else{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
412 i+=4; |
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 res++; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
415 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
416 return res; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
417 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
418 |
307 | 419 /++ |
420 + Get that String, that contains the next codepoint of a String. | |
421 +/ | |
238 | 422 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
|
423 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
424 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
425 dchar[] res = str.toString32( buf, &ate ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
426 consumed = ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
427 return str[ 0 .. ate ]; |
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 |
307 | 430 /++ |
431 + Get first codepoint of a String. If an offset is needed, simply use a slice: | |
432 + --- | |
433 + dchar res = str[ offset .. $ ].firstCodePoint(); | |
434 + --- | |
435 +/ | |
238 | 436 dchar firstCodePoint( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
437 int dummy; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
438 return firstCodePoint( str, dummy ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
439 } |
238 | 440 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
|
441 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
442 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
443 dchar[] res = str.toString32( buf, &ate ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
444 consumed = ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
445 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
|
446 Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); |
109 | 447 } |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
448 assert( ate > 0 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
449 assert( res.length is 1 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
450 return res[0]; |
103 | 451 } |
307 | 452 dchar firstCodePoint( wchar[] str, out int consumed ){ |
453 dchar[1] buf; | |
454 uint ate; | |
455 dchar[] res = str.toString32( buf, &ate ); | |
456 consumed = ate; | |
457 if( ate is 0 || res.length is 0 ){ | |
458 Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); | |
459 } | |
460 assert( ate > 0 ); | |
461 assert( res.length is 1 ); | |
462 return res[0]; | |
463 } | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
464 |
238 | 465 String dcharToString( dchar key ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
466 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
467 buf[0] = key; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
468 return tango.text.convert.Utf.toString( buf ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
469 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
470 |
238 | 471 int codepointCount( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
472 scope dchar[] buf = new dchar[]( str.length ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
473 uint ate; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
474 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
|
475 assert( ate is str.length ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
476 return res.length; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
477 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
478 |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
479 alias tango.text.convert.Utf.toString16 toString16; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
480 alias tango.text.convert.Utf.toString toString; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
481 |
238 | 482 int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ |
307 | 483 return getAbsoluteCodePointOffset( str, startIndex, searchRelCp ) - startIndex; |
484 } | |
485 int getAbsoluteCodePointOffset( String str, int startIndex, int searchRelCp ){ | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
486 int ignore; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
487 int i = startIndex; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
488 if( searchRelCp > 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
489 while( searchRelCp !is 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
490 |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
491 if( ( i < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
492 && ( str[i] & 0x80 ) is 0x00 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
493 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
494 i+=1; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
495 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
496 else if( ( i+1 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
497 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
498 && (( str[i ] & 0xE0 ) is 0xC0 )) |
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 i+=2; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
501 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
502 else if( ( i+2 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
503 && (( str[i+2] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
504 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
505 && (( str[i ] & 0xF0 ) is 0xE0 )) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
506 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
507 i+=3; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
508 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
509 else if(( i+3 < str.length ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
510 && (( str[i+3] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
511 && (( str[i+2] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
512 && (( str[i+1] & 0xC0 ) is 0x80 ) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
513 && (( str[i ] & 0xF8 ) is 0xF0 )) |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
514 { |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
515 i+=4; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
516 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
517 else{ |
285
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
518 Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); |
246
f08216d53777
Fix merge bug in TextLayout
Frank Benoit <benoit@tionex.de>
parents:
245
diff
changeset
|
519 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
|
520 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
521 searchRelCp--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
522 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
523 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
524 else if( searchRelCp < 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
525 while( searchRelCp !is 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
526 do{ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
527 i--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
528 if( i < 0 ){ |
307 | 529 return startIndex-1; |
285
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
530 //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
531 //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
|
532 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
533 } while(( str[i] & 0xC0 ) is 0x80 ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
534 searchRelCp++; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
535 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
536 } |
307 | 537 return i; |
538 } | |
539 int getAbsoluteCodePointOffset( wchar[] str, int startIndex, int searchRelCp ){ | |
540 int ignore; | |
541 int i = startIndex; | |
542 if( searchRelCp > 0 ){ | |
543 while( searchRelCp !is 0 ){ | |
544 | |
545 if( ( i < str.length ) | |
546 && ( str[i] & 0xD800 ) !is 0xD800 ) | |
547 { | |
548 i+=1; | |
549 } | |
550 else if( ( i+1 < str.length ) | |
551 && (( str[i+1] & 0xDC00 ) is 0xDC00 ) | |
552 && (( str[i ] & 0xDC00 ) is 0xD800 )) | |
553 { | |
554 i+=2; | |
555 } | |
556 else{ | |
557 Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); | |
558 tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); | |
559 } | |
560 searchRelCp--; | |
561 } | |
562 } | |
563 else if( searchRelCp < 0 ){ | |
564 while( searchRelCp !is 0 ){ | |
565 do{ | |
566 i--; | |
567 if( i < 0 ){ | |
568 return startIndex-1; | |
569 //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); | |
570 //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); | |
571 } | |
572 } while(( str[i] & 0xDC00 ) is 0xDC00 ); | |
573 searchRelCp++; | |
574 } | |
575 } | |
576 return i; | |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
577 } |
311 | 578 dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp ){ |
579 int dummy; | |
580 return getRelativeCodePoint( str, startIndex, dummy ); | |
581 } | |
238 | 582 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
|
583 relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
584 int ignore; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
585 return firstCodePoint( str[ startIndex+relIndex .. $ ], ignore ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
586 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
587 |
238 | 588 int utf8AdjustOffset( String str, int offset ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
589 if( str.length <= offset || offset <= 0 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
590 return offset; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
591 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
592 while(( str[offset] & 0xC0 ) is 0x80 ){ |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
593 offset--; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
594 } |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
595 return offset; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
596 } |
285
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
597 int utf8OffsetIncr( String str, int offset ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
598 int res = offset +1; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
599 if( str.length <= res || res <= 0 ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
600 return res; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
601 } |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
602 int tries = 4; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
603 while(( str[res] & 0xC0 ) is 0x80 ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
604 res++; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
605 assert( tries-- > 0 ); |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
606 } |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
607 return res; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
608 } |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
609 int utf8OffsetDecr( String str, int offset ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
610 int res = offset-1; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
611 if( str.length <= res || res <= 0 ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
612 return res; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
613 } |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
614 int tries = 4; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
615 while(( str[res] & 0xC0 ) is 0x80 ){ |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
616 res--; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
617 assert( tries-- > 0 ); |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
618 } |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
619 Trace.formatln( "utf8OffsetDecr {}->{}", offset, res ); |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
620 Trace.memory( str ); |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
621 return res; |
75cb516e281e
StyledText fixes from dwt-win:
Frank Benoit <benoit@tionex.de>
parents:
283
diff
changeset
|
622 } |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
623 |
311 | 624 class Character { |
625 public static bool isUpperCase( dchar c ){ | |
626 implMissing( __FILE__, __LINE__); | |
627 return false; | |
628 } | |
629 public static dchar toUpperCase( dchar c ){ | |
630 dchar[] r = tango.text.Unicode.toUpper( [c] ); | |
631 return r[0]; | |
632 } | |
633 public static dchar toLowerCase( dchar c ){ | |
634 dchar[] r = tango.text.Unicode.toLower( [c] ); | |
635 return r[0]; | |
636 } | |
637 public static bool isWhitespace( dchar c ){ | |
638 return tango.text.Unicode.isWhitespace( c ); | |
639 } | |
640 public static bool isDigit( dchar c ){ | |
641 return tango.text.Unicode.isDigit( c ); | |
642 } | |
643 public static bool isLetterOrDigit( dchar c ){ | |
644 return isDigit(c) || isLetter(c); | |
645 } | |
646 public static bool isUnicodeIdentifierPart(char ch){ | |
647 implMissing( __FILE__, __LINE__); | |
648 return false; | |
649 } | |
650 public static bool isUnicodeIdentifierStart(char ch){ | |
651 implMissing( __FILE__, __LINE__); | |
652 return false; | |
653 } | |
654 public static bool isIdentifierIgnorable(char ch){ | |
655 implMissing( __FILE__, __LINE__); | |
656 return false; | |
657 } | |
658 public static bool isJavaIdentifierPart(char ch){ | |
659 implMissing( __FILE__, __LINE__); | |
660 return false; | |
661 } | |
662 | |
663 this( char c ){ | |
664 // must be correct for container storage | |
665 implMissing( __FILE__, __LINE__); | |
666 } | |
667 } | |
668 | |
669 String new_String( String cont, int offset, int len ){ | |
670 return cont[ offset .. offset+len ].dup; | |
671 } | |
672 String new_String( String cont ){ | |
673 return cont.dup; | |
674 } | |
675 String String_valueOf( bool v ){ | |
676 return v ? "true" : "false"; | |
677 } | |
678 String String_valueOf( int v ){ | |
679 return tango.text.convert.Integer.toString(v); | |
680 } | |
681 String String_valueOf( long v ){ | |
682 return tango.text.convert.Integer.toString(v); | |
683 } | |
684 String String_valueOf( float v ){ | |
685 return tango.text.convert.Float.toString(v); | |
686 } | |
687 String String_valueOf( double v ){ | |
688 return tango.text.convert.Float.toString(v); | |
689 } | |
690 String String_valueOf( dchar v ){ | |
691 return dcharToString(v); | |
692 } | |
693 String String_valueOf( char[] v ){ | |
694 return v.dup; | |
695 } | |
696 String String_valueOf( char[] v, int offset, int len ){ | |
697 return v[ offset .. offset+len ].dup; | |
698 } | |
699 String String_valueOf( Object v ){ | |
700 return v is null ? "null" : v.toString(); | |
701 } | |
219 | 702 bool CharacterIsDefined( dchar ch ){ |
703 return (ch in tango.text.UnicodeData.unicodeData) !is null; | |
704 } | |
238 | 705 dchar CharacterFirstToLower( String str ){ |
179
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
706 int consumed; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
707 return CharacterFirstToLower( str, consumed ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
708 } |
238 | 709 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
|
710 dchar[1] buf; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
711 buf[0] = firstCodePoint( str, consumed ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
712 dchar[] r = tango.text.Unicode.toLower( buf ); |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
713 return r[0]; |
e4e5dea57644
Add several functions to support utf8 stuff
Frank Benoit <benoit@tionex.de>
parents:
158
diff
changeset
|
714 } |
311 | 715 int length( String str ){ |
716 return str.length; | |
717 } | |
103 | 718 dchar CharacterToLower( dchar c ){ |
719 dchar[] r = tango.text.Unicode.toLower( [c] ); | |
720 return r[0]; | |
721 } | |
722 dchar CharacterToUpper( dchar c ){ | |
723 dchar[] r = tango.text.Unicode.toUpper( [c] ); | |
724 return r[0]; | |
725 } | |
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
|
726 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
|
727 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
|
728 } |
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
|
729 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
|
730 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
|
731 } |
219 | 732 bool CharacterIsLetter( dchar c ){ |
733 return tango.text.Unicode.isLetter( c ); | |
734 } | |
238 | 735 public String toUpperCase( String str ){ |
219 | 736 return tango.text.Unicode.toUpper( str ); |
737 } | |
26 | 738 |
311 | 739 public String replaceFirst( String str, String regex, String replacement ){ |
740 implMissing(__FILE__,__LINE__); | |
741 return str; | |
742 } | |
743 | |
238 | 744 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
|
745 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
|
746 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
|
747 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
|
748 } |
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
|
749 |
238 | 750 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
|
751 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
|
752 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
|
753 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
|
754 } |
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
|
755 |
238 | 756 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
|
757 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
|
758 } |
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
|
759 |
238 | 760 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
|
761 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
|
762 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
|
763 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
|
764 } |
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
|
765 |
238 | 766 public int lastIndexOf(String str, char ch){ |
190 | 767 return lastIndexOf( str, ch, str.length ); |
768 } | |
238 | 769 public int lastIndexOf(String str, char ch, int formIndex){ |
190 | 770 int res = tango.text.Util.locatePrior( str, ch, formIndex ); |
771 if( res is str.length ) res = -1; | |
772 return res; | |
773 } | |
238 | 774 public int lastIndexOf(String str, String ch ){ |
219 | 775 return lastIndexOf( str, ch, str.length ); |
776 } | |
238 | 777 public int lastIndexOf(String str, String ch, int start ){ |
219 | 778 int res = tango.text.Util.locatePatternPrior( str, ch, start ); |
779 if( res is str.length ) res = -1; | |
780 return res; | |
781 } | |
190 | 782 |
311 | 783 public String replaceAll( String str, String regex, String replacement ){ |
784 implMissing(__FILE__,__LINE__); | |
785 return null; | |
786 } | |
238 | 787 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
|
788 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
|
789 } |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
790 |
238 | 791 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
|
792 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
|
793 } |
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 |
238 | 795 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
|
796 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
|
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 |
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
|
799 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
|
800 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
|
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 |
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
|
803 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
|
804 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
|
805 } |
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 |
238 | 807 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
|
808 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
|
809 } |
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
|
810 |
238 | 811 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
|
812 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
|
813 } |
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
|
814 |
311 | 815 public char[] toCharArray( String str ){ |
816 return 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
|
817 } |
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
|
818 |
238 | 819 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
|
820 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
|
821 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
|
822 } |
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
|
823 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
|
824 } |
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
|
825 |
238 | 826 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
|
827 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
|
828 } |
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
|
829 |
238 | 830 public bool equalsIgnoreCase( String src, String other ){ |
190 | 831 return tango.text.Unicode.toFold(src) == tango.text.Unicode.toFold(other); |
832 } | |
833 | |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
834 public int compareToIgnoreCase( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
835 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
|
836 } |
250 | 837 public int compareTo( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
838 return typeid(String).compare( cast(void*)&src, cast(void*)&other ); |
250 | 839 } |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
840 |
238 | 841 public bool startsWith( String src, String pattern ){ |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
842 if( src.length < pattern.length ){ |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
843 return false; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
844 } |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
845 return src[ 0 .. pattern.length ] == pattern; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
846 } |
210 | 847 |
238 | 848 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
|
849 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
|
850 } |
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
|
851 |
238 | 852 public hash_t toHash( String src ){ |
853 return typeid(String).getHash(&src); | |
191 | 854 } |
855 | |
238 | 856 public String trim( String str ){ |
210 | 857 return tango.text.Util.trim( str ).dup; |
858 } | |
238 | 859 public String intern( String str ){ |
219 | 860 return str; |
861 } | |
210 | 862 |
313 | 863 /++ |
864 + This is like tango.stdc.stringz.toStringz, but in case of an empty input string, | |
865 + this function returns a pointer to a null value instead of a null ptr. | |
866 +/ | |
238 | 867 public char* toStringzValidPtr( String src ){ |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
868 if( src ){ |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
869 return src.toStringz(); |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
870 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
871 else{ |
238 | 872 static const String nullPtr = "\0"; |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
873 return nullPtr.ptr; |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
874 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
875 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
876 |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
877 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
|
878 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
|
879 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
|
880 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
|
881 |
238 | 882 static String toHex(uint value, bool prefix = true, int radix = 8){ |
262 | 883 return tango.text.convert.Integer.toString( |
884 value, | |
885 radix is 10 ? "d" : | |
886 radix is 8 ? "o" : | |
887 radix is 16 ? "x" : | |
888 "d" ); | |
889 } | |
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
|
890 |
219 | 891 class RuntimeException : Exception { |
238 | 892 this( String e = null){ |
219 | 893 super(e); |
894 } | |
895 this( Exception e ){ | |
896 super(e.toString); | |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
897 next = e; |
219 | 898 } |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
899 public Exception getCause() { |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
900 return next; |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
901 } |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
902 |
219 | 903 } |
904 class IndexOutOfBoundsException : Exception { | |
238 | 905 this( String e = null){ |
219 | 906 super(e); |
907 } | |
908 } | |
909 | |
910 class UnsupportedOperationException : RuntimeException { | |
238 | 911 this( String e = null){ |
219 | 912 super(e); |
913 } | |
914 this( Exception e ){ | |
915 super(e.toString); | |
916 } | |
917 } | |
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
|
918 class NumberFormatException : IllegalArgumentException { |
238 | 919 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
|
920 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
|
921 } |
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
|
922 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
|
923 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
|
924 } |
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
|
925 } |
219 | 926 class NullPointerException : Exception { |
238 | 927 this( String e = null ){ |
219 | 928 super(e); |
929 } | |
930 this( Exception e ){ | |
931 super(e.toString); | |
932 } | |
933 } | |
934 class IllegalStateException : Exception { | |
238 | 935 this( String e = null ){ |
219 | 936 super(e); |
937 } | |
938 this( Exception e ){ | |
939 super(e.toString); | |
940 } | |
941 } | |
942 class InterruptedException : Exception { | |
238 | 943 this( String e = null ){ |
219 | 944 super(e); |
945 } | |
946 this( Exception e ){ | |
947 super(e.toString); | |
948 } | |
949 } | |
950 class InvocationTargetException : Exception { | |
951 Exception cause; | |
238 | 952 this( Exception e = null, String msg = null ){ |
219 | 953 super(msg); |
954 cause = e; | |
955 } | |
956 | |
957 alias getCause getTargetException; | |
958 Exception getCause(){ | |
959 return cause; | |
960 } | |
961 } | |
962 class MissingResourceException : Exception { | |
238 | 963 String classname; |
964 String key; | |
965 this( String msg, String classname, String key ){ | |
219 | 966 super(msg); |
967 this.classname = classname; | |
968 this.key = key; | |
969 } | |
970 } | |
971 class ParseException : Exception { | |
238 | 972 this( String e = null ){ |
219 | 973 super(e); |
974 } | |
975 } | |
311 | 976 class ClassCastException : Exception { |
977 this( String e = null ){ | |
978 super(e); | |
979 } | |
980 } | |
219 | 981 |
982 interface Cloneable{ | |
983 } | |
984 | |
985 interface Comparable { | |
986 int compareTo(Object o); | |
987 } | |
988 interface Comparator { | |
989 int compare(Object o1, Object o2); | |
990 } | |
991 interface EventListener{ | |
992 } | |
993 | |
994 class EventObject { | |
995 protected Object source; | |
996 | |
997 public this(Object source) { | |
998 if (source is null) | |
999 throw new IllegalArgumentException( "null arg" ); | |
1000 this.source = source; | |
1001 } | |
1002 | |
1003 public Object getSource() { | |
1004 return source; | |
1005 } | |
1006 | |
238 | 1007 public override String toString() { |
219 | 1008 return this.classinfo.name ~ "[source=" ~ source.toString() ~ "]"; |
1009 } | |
1010 } | |
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
|
1011 |
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
|
1012 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
|
1013 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
|
1014 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
|
1015 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
|
1016 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
|
1017 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
|
1018 } |
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
|
1019 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
|
1020 |
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
|
1021 size_t RuntimeTotalMemory(){ |
228 | 1022 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
|
1023 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
|
1024 } |
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
|
1025 |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1026 String ExceptionGetLocalizedMessage( Exception e ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1027 return e.msg; |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1028 } |
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
|
1029 |
219 | 1030 void ExceptionPrintStackTrace( Exception e ){ |
1031 ExceptionPrintStackTrace( e, Stderr ); | |
1032 } | |
1033 void ExceptionPrintStackTrace( Exception e, Print!(char) print ){ | |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1034 Exception exception = e; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1035 while( exception !is null ){ |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1036 print.formatln( "Exception in {}({}): {}", exception.file, exception.line, exception.msg ); |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1037 if( exception.info !is null ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1038 foreach( msg; exception.info ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1039 print.formatln( "trc {}", msg ); |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1040 } |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1041 } |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1042 exception = exception.next; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1043 } |
219 | 1044 } |
1045 | |
311 | 1046 class Reader{ |
1047 protected Object lock; | |
1048 protected this(){ | |
1049 implMissing(__FILE__,__LINE__); | |
1050 } | |
1051 protected this(Object lock){ | |
1052 implMissing(__FILE__,__LINE__); | |
1053 } | |
1054 abstract void close(); | |
1055 void mark(int readAheadLimit){ | |
1056 implMissing(__FILE__,__LINE__); | |
1057 } | |
1058 bool markSupported(){ | |
1059 implMissing(__FILE__,__LINE__); | |
1060 return false; | |
1061 } | |
1062 int read(){ | |
1063 implMissing(__FILE__,__LINE__); | |
1064 return 0; | |
1065 } | |
1066 int read(char[] cbuf){ | |
1067 implMissing(__FILE__,__LINE__); | |
1068 return 0; | |
1069 } | |
1070 abstract int read(char[] cbuf, int off, int len); | |
1071 bool ready(){ | |
1072 implMissing(__FILE__,__LINE__); | |
1073 return false; | |
1074 } | |
1075 void reset(){ | |
1076 implMissing(__FILE__,__LINE__); | |
1077 } | |
1078 long skip(long n){ | |
1079 implMissing(__FILE__,__LINE__); | |
1080 return 0; | |
1081 } | |
219 | 1082 } |
1083 interface Writer{ | |
1084 } | |
1085 | |
1086 | |
1087 class Collator : Comparator { | |
1088 public static Collator getInstance(){ | |
1089 implMissing( __FILE__, __LINE__ ); | |
1090 return null; | |
1091 } | |
1092 private this(){ | |
1093 } | |
1094 int compare(Object o1, Object o2){ | |
1095 implMissing( __FILE__, __LINE__ ); | |
1096 return 0; | |
1097 } | |
1098 } | |
1099 | |
1100 template arraycast(T) { | |
1101 T[] arraycast(U) (U[] u) { | |
1102 static if ( | |
1103 (is (T == interface ) && is (U == interface )) || | |
1104 (is (T == class ) && is (U == class ))) { | |
1105 return(cast(T[])u); | |
1106 } | |
1107 else { | |
1108 int l = u.length; | |
1109 T[] res; | |
1110 res.length = l; | |
1111 for (int i = 0; i < l; i++) { | |
1112 res[i] = cast(T)u[i]; | |
1113 } | |
1114 return(res); | |
1115 } | |
1116 } | |
1117 } | |
1118 | |
238 | 1119 String stringcast( Object o ){ |
219 | 1120 if( auto str = cast(ArrayWrapperString) o ){ |
1121 return str.array; | |
1122 } | |
1123 return null; | |
1124 } | |
238 | 1125 String[] stringcast( Object[] objs ){ |
1126 String[] res = new String[](objs.length); | |
219 | 1127 foreach( idx, obj; objs ){ |
1128 res[idx] = stringcast(obj); | |
1129 } | |
1130 return res; | |
1131 } | |
238 | 1132 ArrayWrapperString stringcast( String str ){ |
219 | 1133 return new ArrayWrapperString( str ); |
1134 } | |
238 | 1135 ArrayWrapperString[] stringcast( String[] strs ){ |
219 | 1136 ArrayWrapperString[] res = new ArrayWrapperString[ strs.length ]; |
1137 foreach( idx, str; strs ){ | |
1138 res[idx] = stringcast(str); | |
1139 } | |
1140 return res; | |
1141 } | |
1142 | |
292
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1143 String[] stringArrayFromObject( Object obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1144 if( auto wrapper = cast(ArrayWrapperString2)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1145 return wrapper.array; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1146 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1147 if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1148 String[] res = new String[ wrapper.array.length ]; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1149 foreach( idx, o; wrapper.array ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1150 if( auto swrapper = cast(ArrayWrapperString) o ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1151 res[idx] = swrapper.array; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1152 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1153 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1154 return res; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1155 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1156 assert( obj is null ); // if not null, it was the wrong type |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1157 return null; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1158 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1159 |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1160 T[] arrayFromObject(T)( Object obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1161 if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1162 T[] res = new T[ wrapper.array.length ]; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1163 foreach( idx, o; wrapper.array ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1164 res[idx] = cast(T)o; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1165 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1166 return res; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1167 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1168 assert( obj is null ); // if not null, it was the wrong type |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1169 return null; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1170 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1171 |
219 | 1172 |
223 | 1173 bool ArrayEquals(T)( T[] a, T[] b ){ |
1174 if( a.length !is b.length ){ | |
1175 return false; | |
1176 } | |
1177 for( int i = 0; i < a.length; i++ ){ | |
1178 static if( is( T==class) || is(T==interface)){ | |
1179 if( a[i] !is null && b[i] !is null ){ | |
1180 if( a[i] != b[i] ){ | |
1181 return false; | |
1182 } | |
1183 } | |
1184 else if( a[i] is null && b[i] is null ){ | |
1185 } | |
1186 else{ | |
1187 return false; | |
1188 } | |
1189 } | |
1190 else{ | |
1191 if( a[i] != b[i] ){ | |
1192 return false; | |
1193 } | |
1194 } | |
1195 } | |
226 | 1196 return true; |
223 | 1197 } |
1198 | |
311 | 1199 /+int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){ |
219 | 1200 int idx; |
1201 foreach( e; s ){ | |
1202 if( e == src ){ | |
1203 return idx; | |
1204 } | |
1205 idx++; | |
1206 } | |
1207 return -1; | |
311 | 1208 }+/ |
1209 | |
219 | 1210 int arrayIndexOf(T)( T[] arr, T v ){ |
1211 int res = -1; | |
1212 int idx = 0; | |
1213 foreach( p; arr ){ | |
1214 if( p == v){ | |
1215 res = idx; | |
1216 break; | |
1217 } | |
1218 idx++; | |
1219 } | |
1220 return res; | |
1221 } | |
1222 | |
311 | 1223 // int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){ |
1224 // int res = -1; | |
1225 // int idx = 0; | |
1226 // foreach( p; seq ){ | |
1227 // if( p == v){ | |
1228 // res = idx; | |
1229 // break; | |
1230 // } | |
1231 // idx++; | |
1232 // } | |
1233 // return res; | |
1234 // } | |
219 | 1235 |
238 | 1236 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ |
229 | 1237 auto e = new Exception( null ); |
1238 int idx = 0; | |
1239 const start = 3; | |
1240 foreach( msg; e.info ){ | |
1241 if( idx >= start && idx < start+deepth ) { | |
1242 Trace.formatln( "{}: {}", prefix, msg ); | |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1243 } |
229 | 1244 idx++; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1245 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1246 } |
219 | 1247 |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1248 struct ImportData{ |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1249 void[] data; |
238 | 1250 String name; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1251 |
238 | 1252 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
|
1253 ImportData res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1254 res.data = data; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1255 res.name = name; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1256 return res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1257 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1258 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1259 |
238 | 1260 template getImportData(String name ){ |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1261 const ImportData getImportData = ImportData( import(name), name ); |
238 | 1262 } |
283
05e48e1e65d1
Double constant values for Draw2D
Frank Benoit <benoit@tionex.de>
parents:
276
diff
changeset
|
1263 |
310
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1264 interface CharSequence { |
311 | 1265 char charAt(int index); |
310
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1266 int length(); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1267 CharSequence subSequence(int start, int end); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1268 String toString(); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1269 } |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1270 |
311 | 1271 class StringCharSequence : CharSequence { |
1272 private String str; | |
1273 this( String str ){ | |
1274 this.str = str; | |
1275 } | |
1276 char charAt(int index){ | |
1277 return str[index]; | |
1278 } | |
1279 int length(){ | |
1280 return str.length; | |
1281 } | |
1282 CharSequence subSequence(int start, int end){ | |
1283 return new StringCharSequence( str[ start .. end ]); | |
1284 } | |
1285 String toString(){ | |
1286 return str; | |
1287 } | |
1288 } | |
1289 | |
1290 |