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