Mercurial > projects > dwt-win
annotate dwt/dwthelper/utils.d @ 23:f5482da87ed8
Image, ImageData
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sun, 27 Jan 2008 17:43:55 +0100 |
parents | 5f2e72114476 |
children | b868bfa989cd |
rev | line source |
---|---|
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
1 /** |
0 | 2 * Authors: Frank Benoit <keinfarbton@googlemail.com> |
3 */ | |
4 module dwt.dwthelper.utils; | |
5 | |
6 public import dwt.dwthelper.System; | |
15 | 7 public import Math = tango.math.Math; |
0 | 8 |
9 import tango.io.Stdout; | |
15 | 10 import tango.stdc.stringz; |
11 import tango.text.Util; | |
0 | 12 import tango.text.Unicode; |
15 | 13 import tango.text.convert.Utf; |
14 import tango.core.Exception; | |
0 | 15 import tango.stdc.stdlib : exit; |
16 | |
17 void implMissing( char[] file, uint line ){ | |
18 Stderr.formatln( "implementation missing in file {} line {}", file, line ); | |
19 Stderr.formatln( "exiting ..." ); | |
20 exit(1); | |
21 } | |
22 | |
23 abstract class ArrayWrapper{ | |
24 } | |
25 | |
26 class ArrayWrapperT(T) : ArrayWrapper { | |
27 public T[] array; | |
28 public this( T[] data ){ | |
29 array = data; | |
30 } | |
31 } | |
32 | |
33 alias ArrayWrapperT!(byte) ArrayWrapperByte; | |
34 alias ArrayWrapperT!(int) ArrayWrapperInt; | |
35 alias ArrayWrapperT!(Object) ArrayWrapperObject; | |
36 alias ArrayWrapperT!(char) ArrayWrapperString; | |
37 alias ArrayWrapperT!(char[]) ArrayWrapperString2; | |
38 | |
39 dchar getFirstCodepoint( char[] str ){ | |
40 foreach( dchar d; str ){ | |
41 return d; | |
42 } | |
43 } | |
44 dchar CharacterToLower( dchar c ){ | |
45 dchar[] r = tango.text.Unicode.toLower( [c] ); | |
46 return r[0]; | |
47 } | |
48 dchar CharacterToUpper( dchar c ){ | |
49 dchar[] r = tango.text.Unicode.toUpper( [c] ); | |
50 return r[0]; | |
51 } | |
52 | |
15 | 53 public int indexOf( char[] str, char searched ){ |
54 int res = tango.text.Util.locate( str, searched ); | |
55 if( res is str.length ) res = -1; | |
56 return res; | |
57 } | |
58 | |
59 public int indexOf( char[] str, char searched, int startpos ){ | |
60 int res = tango.text.Util.locate( str, searched, startpos ); | |
61 if( res is str.length ) res = -1; | |
62 return res; | |
63 } | |
64 | |
65 public int indexOf(char[] str, char[] ch, int start){ | |
66 int res = tango.text.Util.locatePattern( str, ch, start ); | |
67 if( res is str.length ) res = -1; | |
68 return res; | |
69 } | |
70 | |
71 public char[] substring( char[] str, int start ){ | |
72 return str[ start .. $ ].dup; | |
73 } | |
74 | |
75 public char[] substring( char[] str, int start, int end ){ | |
76 return str[ start .. end ].dup; | |
77 } | |
78 | |
79 public wchar[] substring( wchar[] str, int start ){ | |
80 return str[ start .. $ ].dup; | |
81 } | |
82 | |
83 public wchar[] substring( wchar[] str, int start, int end ){ | |
84 return str[ start .. end ].dup; | |
85 } | |
86 | |
87 public char charAt( char[] str, int pos ){ | |
88 return str[ pos ]; | |
89 } | |
90 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
91 public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
23 | 92 dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
93 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
94 |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
95 public bool endsWith( char[] src, char[] pattern ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
96 if( src.length < pattern.length ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
97 return false; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
98 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
99 return src[ $-pattern.length .. $ ] == pattern; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
100 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
101 |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
102 public char[] toLowerCase( char[] src ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
103 return tango.text.Unicode.toLower( src ); |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
104 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
105 |
15 | 106 static char[] toHex(uint value, bool prefix = true, int radix = 8){ |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
107 return tango.text.convert.Integer.toString( |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
108 value, |
15 | 109 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
110 radix is 8 ? tango.text.convert.Integer.Style.Octal : | |
111 radix is 16 ? tango.text.convert.Integer.Style.Hex : | |
112 tango.text.convert.Integer.Style.Signed, | |
113 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None | |
114 ); | |
115 } | |
116 | |
117 class NumberFormatException : IllegalArgumentException { | |
118 this( char[] e ){ | |
119 super(e); | |
120 } | |
121 this( TracedException e ){ | |
122 super(e.toString); | |
123 } | |
124 } | |
125 | |
126 | |
127 | |
128 | |
129 | |
130 |