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