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