Mercurial > projects > dwt-linux
annotate dwt/dwthelper/utils.d @ 339:c317081df76f
Mozilla module complete (first phase complete)
author | John Reimer <terminal.node@gmail.com> |
---|---|
date | Sat, 25 Oct 2008 21:01:54 -0700 |
parents | 6f57d3b9947c |
children | 96243e3ebcf0 |
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 |
317 | 815 public wchar[] toWCharArray( String str ){ |
816 return toString16(str); | |
817 } | |
818 | |
311 | 819 public char[] toCharArray( String str ){ |
820 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
|
821 } |
de2578a843a7
Tango update to rev 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 |
238 | 823 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
|
824 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
|
825 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
|
826 } |
de2578a843a7
Tango update to rev 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[ $-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
|
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 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
|
831 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
|
832 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
833 |
238 | 834 public bool equalsIgnoreCase( String src, String other ){ |
190 | 835 return tango.text.Unicode.toFold(src) == tango.text.Unicode.toFold(other); |
836 } | |
837 | |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
838 public int compareToIgnoreCase( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
839 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
|
840 } |
250 | 841 public int compareTo( String src, String other ){ |
254
8bca790583c3
Fix string compare in dwthelper/utils
Frank Benoit <benoit@tionex.de>
parents:
250
diff
changeset
|
842 return typeid(String).compare( cast(void*)&src, cast(void*)&other ); |
250 | 843 } |
245
239b9a56bd5f
Added the compareToIgnoreCase to utils
Frank Benoit <benoit@tionex.de>
parents:
238
diff
changeset
|
844 |
238 | 845 public bool startsWith( String src, String pattern ){ |
200
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
846 if( src.length < pattern.length ){ |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
847 return false; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
848 } |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
849 return src[ 0 .. pattern.length ] == pattern; |
08789b28bdf3
import dwt.dwthelper.utils now explicit
Frank Benoit <benoit@tionex.de>
parents:
191
diff
changeset
|
850 } |
210 | 851 |
238 | 852 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
|
853 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
|
854 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
855 |
238 | 856 public hash_t toHash( String src ){ |
857 return typeid(String).getHash(&src); | |
191 | 858 } |
859 | |
238 | 860 public String trim( String str ){ |
210 | 861 return tango.text.Util.trim( str ).dup; |
862 } | |
238 | 863 public String intern( String str ){ |
219 | 864 return str; |
865 } | |
210 | 866 |
313 | 867 /++ |
868 + This is like tango.stdc.stringz.toStringz, but in case of an empty input string, | |
869 + this function returns a pointer to a null value instead of a null ptr. | |
870 +/ | |
238 | 871 public char* toStringzValidPtr( String src ){ |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
872 if( src ){ |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
873 return src.toStringz(); |
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 else{ |
238 | 876 static const String nullPtr = "\0"; |
207
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
877 return nullPtr.ptr; |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
878 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
879 } |
12feeed18183
Allow Label.setText with null argument.
Frank Benoit <benoit@tionex.de>
parents:
200
diff
changeset
|
880 |
255
5a30aa9820f3
removed tango.stdc.stringz imports and allow null for arrays and string arguments.
Frank Benoit <benoit@tionex.de>
parents:
254
diff
changeset
|
881 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
|
882 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
|
883 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
|
884 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
|
885 |
238 | 886 static String toHex(uint value, bool prefix = true, int radix = 8){ |
262 | 887 return tango.text.convert.Integer.toString( |
888 value, | |
889 radix is 10 ? "d" : | |
890 radix is 8 ? "o" : | |
891 radix is 16 ? "x" : | |
892 "d" ); | |
893 } | |
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
|
894 |
219 | 895 class RuntimeException : Exception { |
238 | 896 this( String e = null){ |
219 | 897 super(e); |
898 } | |
899 this( Exception e ){ | |
900 super(e.toString); | |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
901 next = e; |
219 | 902 } |
225
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
903 public Exception getCause() { |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
904 return next; |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
905 } |
5366f8db1eda
RuntimeException with getCause
Frank Benoit <benoit@tionex.de>
parents:
223
diff
changeset
|
906 |
219 | 907 } |
908 class IndexOutOfBoundsException : Exception { | |
238 | 909 this( String e = null){ |
219 | 910 super(e); |
911 } | |
912 } | |
913 | |
914 class UnsupportedOperationException : RuntimeException { | |
238 | 915 this( String e = null){ |
219 | 916 super(e); |
917 } | |
918 this( Exception e ){ | |
919 super(e.toString); | |
920 } | |
921 } | |
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
|
922 class NumberFormatException : IllegalArgumentException { |
238 | 923 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
|
924 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
|
925 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
926 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
|
927 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
|
928 } |
de2578a843a7
Tango update to rev 3158, TracedException>Exception, fromUtf8z>fromStringz,Fix Bug in MenuItem Thanx to nascent for the report.
Frank Benoit <benoit@tionex.de>
parents:
109
diff
changeset
|
929 } |
219 | 930 class NullPointerException : Exception { |
238 | 931 this( String e = null ){ |
219 | 932 super(e); |
933 } | |
934 this( Exception e ){ | |
935 super(e.toString); | |
936 } | |
937 } | |
938 class IllegalStateException : Exception { | |
238 | 939 this( String e = null ){ |
219 | 940 super(e); |
941 } | |
942 this( Exception e ){ | |
943 super(e.toString); | |
944 } | |
945 } | |
946 class InterruptedException : Exception { | |
238 | 947 this( String e = null ){ |
219 | 948 super(e); |
949 } | |
950 this( Exception e ){ | |
951 super(e.toString); | |
952 } | |
953 } | |
954 class InvocationTargetException : Exception { | |
955 Exception cause; | |
238 | 956 this( Exception e = null, String msg = null ){ |
219 | 957 super(msg); |
958 cause = e; | |
959 } | |
960 | |
961 alias getCause getTargetException; | |
962 Exception getCause(){ | |
963 return cause; | |
964 } | |
965 } | |
966 class MissingResourceException : Exception { | |
238 | 967 String classname; |
968 String key; | |
969 this( String msg, String classname, String key ){ | |
219 | 970 super(msg); |
971 this.classname = classname; | |
972 this.key = key; | |
973 } | |
974 } | |
975 class ParseException : Exception { | |
238 | 976 this( String e = null ){ |
219 | 977 super(e); |
978 } | |
979 } | |
311 | 980 class ClassCastException : Exception { |
981 this( String e = null ){ | |
982 super(e); | |
983 } | |
984 } | |
219 | 985 |
986 interface Cloneable{ | |
987 } | |
988 | |
989 interface Comparable { | |
990 int compareTo(Object o); | |
991 } | |
992 interface Comparator { | |
993 int compare(Object o1, Object o2); | |
994 } | |
995 interface EventListener{ | |
996 } | |
997 | |
998 class EventObject { | |
999 protected Object source; | |
1000 | |
1001 public this(Object source) { | |
1002 if (source is null) | |
1003 throw new IllegalArgumentException( "null arg" ); | |
1004 this.source = source; | |
1005 } | |
1006 | |
1007 public Object getSource() { | |
1008 return source; | |
1009 } | |
1010 | |
238 | 1011 public override String toString() { |
219 | 1012 return this.classinfo.name ~ "[source=" ~ source.toString() ~ "]"; |
1013 } | |
1014 } | |
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
|
1015 |
de2578a843a7
Tango update to rev 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 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
|
1017 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
|
1018 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
|
1019 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
|
1020 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
|
1021 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
|
1022 } |
de2578a843a7
Tango update to rev 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 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
|
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 size_t RuntimeTotalMemory(){ |
228 | 1026 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
|
1027 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
|
1028 } |
de2578a843a7
Tango update to rev 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 |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1030 String ExceptionGetLocalizedMessage( Exception e ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1031 return e.msg; |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1032 } |
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
|
1033 |
219 | 1034 void ExceptionPrintStackTrace( Exception e ){ |
1035 ExceptionPrintStackTrace( e, Stderr ); | |
1036 } | |
1037 void ExceptionPrintStackTrace( Exception e, Print!(char) print ){ | |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1038 Exception exception = e; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1039 while( exception !is null ){ |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1040 print.formatln( "Exception in {}({}): {}", exception.file, exception.line, exception.msg ); |
249
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1041 if( exception.info !is null ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1042 foreach( msg; exception.info ){ |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1043 print.formatln( "trc {}", msg ); |
e1ec1581e355
Fix ExceptionPrintStacktrace
Frank Benoit <benoit@tionex.de>
parents:
246
diff
changeset
|
1044 } |
235
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1045 } |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1046 exception = exception.next; |
b16e1f78a213
ExceptionPrintStackTrace recurses now into .next
Frank Benoit <benoit@tionex.de>
parents:
229
diff
changeset
|
1047 } |
219 | 1048 } |
1049 | |
311 | 1050 class Reader{ |
1051 protected Object lock; | |
1052 protected this(){ | |
1053 implMissing(__FILE__,__LINE__); | |
1054 } | |
1055 protected this(Object lock){ | |
1056 implMissing(__FILE__,__LINE__); | |
1057 } | |
1058 abstract void close(); | |
1059 void mark(int readAheadLimit){ | |
1060 implMissing(__FILE__,__LINE__); | |
1061 } | |
1062 bool markSupported(){ | |
1063 implMissing(__FILE__,__LINE__); | |
1064 return false; | |
1065 } | |
1066 int read(){ | |
1067 implMissing(__FILE__,__LINE__); | |
1068 return 0; | |
1069 } | |
1070 int read(char[] cbuf){ | |
1071 implMissing(__FILE__,__LINE__); | |
1072 return 0; | |
1073 } | |
1074 abstract int read(char[] cbuf, int off, int len); | |
1075 bool ready(){ | |
1076 implMissing(__FILE__,__LINE__); | |
1077 return false; | |
1078 } | |
1079 void reset(){ | |
1080 implMissing(__FILE__,__LINE__); | |
1081 } | |
1082 long skip(long n){ | |
1083 implMissing(__FILE__,__LINE__); | |
1084 return 0; | |
1085 } | |
219 | 1086 } |
1087 interface Writer{ | |
1088 } | |
1089 | |
1090 | |
1091 class Collator : Comparator { | |
1092 public static Collator getInstance(){ | |
1093 implMissing( __FILE__, __LINE__ ); | |
1094 return null; | |
1095 } | |
1096 private this(){ | |
1097 } | |
1098 int compare(Object o1, Object o2){ | |
1099 implMissing( __FILE__, __LINE__ ); | |
1100 return 0; | |
1101 } | |
1102 } | |
1103 | |
1104 template arraycast(T) { | |
1105 T[] arraycast(U) (U[] u) { | |
1106 static if ( | |
1107 (is (T == interface ) && is (U == interface )) || | |
1108 (is (T == class ) && is (U == class ))) { | |
1109 return(cast(T[])u); | |
1110 } | |
1111 else { | |
1112 int l = u.length; | |
1113 T[] res; | |
1114 res.length = l; | |
1115 for (int i = 0; i < l; i++) { | |
1116 res[i] = cast(T)u[i]; | |
1117 } | |
1118 return(res); | |
1119 } | |
1120 } | |
1121 } | |
1122 | |
238 | 1123 String stringcast( Object o ){ |
219 | 1124 if( auto str = cast(ArrayWrapperString) o ){ |
1125 return str.array; | |
1126 } | |
1127 return null; | |
1128 } | |
238 | 1129 String[] stringcast( Object[] objs ){ |
1130 String[] res = new String[](objs.length); | |
219 | 1131 foreach( idx, obj; objs ){ |
1132 res[idx] = stringcast(obj); | |
1133 } | |
1134 return res; | |
1135 } | |
238 | 1136 ArrayWrapperString stringcast( String str ){ |
219 | 1137 return new ArrayWrapperString( str ); |
1138 } | |
238 | 1139 ArrayWrapperString[] stringcast( String[] strs ){ |
219 | 1140 ArrayWrapperString[] res = new ArrayWrapperString[ strs.length ]; |
1141 foreach( idx, str; strs ){ | |
1142 res[idx] = stringcast(str); | |
1143 } | |
1144 return res; | |
1145 } | |
1146 | |
292
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1147 String[] stringArrayFromObject( Object obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1148 if( auto wrapper = cast(ArrayWrapperString2)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1149 return wrapper.array; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1150 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1151 if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1152 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
|
1153 foreach( idx, o; wrapper.array ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1154 if( auto swrapper = cast(ArrayWrapperString) o ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1155 res[idx] = swrapper.array; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1156 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1157 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1158 return res; |
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 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
|
1161 return null; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1162 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1163 |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1164 T[] arrayFromObject(T)( Object obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1165 if( auto wrapper = cast(ArrayWrapperObject)obj ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1166 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
|
1167 foreach( idx, o; wrapper.array ){ |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1168 res[idx] = cast(T)o; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1169 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1170 return res; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1171 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1172 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
|
1173 return null; |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1174 } |
695802b523c0
Adjustements for the container rework in dwt-addons
Frank Benoit <benoit@tionex.de>
parents:
285
diff
changeset
|
1175 |
219 | 1176 |
223 | 1177 bool ArrayEquals(T)( T[] a, T[] b ){ |
1178 if( a.length !is b.length ){ | |
1179 return false; | |
1180 } | |
1181 for( int i = 0; i < a.length; i++ ){ | |
1182 static if( is( T==class) || is(T==interface)){ | |
1183 if( a[i] !is null && b[i] !is null ){ | |
1184 if( a[i] != b[i] ){ | |
1185 return false; | |
1186 } | |
1187 } | |
1188 else if( a[i] is null && b[i] is null ){ | |
1189 } | |
1190 else{ | |
1191 return false; | |
1192 } | |
1193 } | |
1194 else{ | |
1195 if( a[i] != b[i] ){ | |
1196 return false; | |
1197 } | |
1198 } | |
1199 } | |
226 | 1200 return true; |
223 | 1201 } |
1202 | |
311 | 1203 /+int SeqIndexOf(T)( tango.util.collection.model.Seq.Seq!(T) s, T src ){ |
219 | 1204 int idx; |
1205 foreach( e; s ){ | |
1206 if( e == src ){ | |
1207 return idx; | |
1208 } | |
1209 idx++; | |
1210 } | |
1211 return -1; | |
311 | 1212 }+/ |
1213 | |
219 | 1214 int arrayIndexOf(T)( T[] arr, T v ){ |
1215 int res = -1; | |
1216 int idx = 0; | |
1217 foreach( p; arr ){ | |
1218 if( p == v){ | |
1219 res = idx; | |
1220 break; | |
1221 } | |
1222 idx++; | |
1223 } | |
1224 return res; | |
1225 } | |
1226 | |
339
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1227 T[] arrayIndexRemove(T)(T[] arr, uint index) { |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1228 if (n is 0) |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1229 return arr[1..$]; |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1230 if (n > arr.length) |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1231 return arr; |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1232 if (n is arr.length-1) |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1233 return arr[0..n-1]; |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1234 // else |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1235 return arr[0..n] ~ arr[n+1..$]; |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1236 } |
c317081df76f
Mozilla module complete (first phase complete)
John Reimer <terminal.node@gmail.com>
parents:
317
diff
changeset
|
1237 |
311 | 1238 // int seqIndexOf( tango.util.collection.model.Seq.Seq!(Object) seq, Object v ){ |
1239 // int res = -1; | |
1240 // int idx = 0; | |
1241 // foreach( p; seq ){ | |
1242 // if( p == v){ | |
1243 // res = idx; | |
1244 // break; | |
1245 // } | |
1246 // idx++; | |
1247 // } | |
1248 // return res; | |
1249 // } | |
219 | 1250 |
238 | 1251 void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ |
229 | 1252 auto e = new Exception( null ); |
1253 int idx = 0; | |
1254 const start = 3; | |
1255 foreach( msg; e.info ){ | |
1256 if( idx >= start && idx < start+deepth ) { | |
1257 Trace.formatln( "{}: {}", prefix, msg ); | |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1258 } |
229 | 1259 idx++; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1260 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1261 } |
219 | 1262 |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1263 struct ImportData{ |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1264 void[] data; |
238 | 1265 String name; |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1266 |
238 | 1267 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
|
1268 ImportData res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1269 res.data = data; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1270 res.name = name; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1271 return res; |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1272 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1273 } |
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1274 |
238 | 1275 template getImportData(String name ){ |
220
ba054b4a1c55
ImportData for loading compile time images
Frank Benoit <benoit@tionex.de>
parents:
219
diff
changeset
|
1276 const ImportData getImportData = ImportData( import(name), name ); |
238 | 1277 } |
283
05e48e1e65d1
Double constant values for Draw2D
Frank Benoit <benoit@tionex.de>
parents:
276
diff
changeset
|
1278 |
310
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1279 interface CharSequence { |
311 | 1280 char charAt(int index); |
310
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1281 int length(); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1282 CharSequence subSequence(int start, int end); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1283 String toString(); |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1284 } |
7ca3f26319f1
System.out.println and interface CharSequence
Frank Benoit <benoit@tionex.de>
parents:
307
diff
changeset
|
1285 |
311 | 1286 class StringCharSequence : CharSequence { |
1287 private String str; | |
1288 this( String str ){ | |
1289 this.str = str; | |
1290 } | |
1291 char charAt(int index){ | |
1292 return str[index]; | |
1293 } | |
1294 int length(){ | |
1295 return str.length; | |
1296 } | |
1297 CharSequence subSequence(int start, int end){ | |
1298 return new StringCharSequence( str[ start .. end ]); | |
1299 } | |
1300 String toString(){ | |
1301 return str; | |
1302 } | |
1303 } | |
1304 | |
1305 |