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