Mercurial > projects > dwt-win
annotate dwt/dwthelper/utils.d @ 28:b868bfa989cd
Cursor
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 28 Jan 2008 00:22:22 +0100 |
parents | f5482da87ed8 |
children | 1e14cb29290a |
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 |
28 | 95 public wchar[] toCharArray( char[] str ){ |
96 return StrToWCHARs( str ); | |
97 } | |
98 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
99 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
|
100 if( src.length < pattern.length ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
101 return false; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
102 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
103 return src[ $-pattern.length .. $ ] == pattern; |
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 |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
106 public char[] toLowerCase( char[] src ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
107 return tango.text.Unicode.toLower( src ); |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
108 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
109 |
15 | 110 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
|
111 return tango.text.convert.Integer.toString( |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
112 value, |
15 | 113 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
114 radix is 8 ? tango.text.convert.Integer.Style.Octal : | |
115 radix is 16 ? tango.text.convert.Integer.Style.Hex : | |
116 tango.text.convert.Integer.Style.Signed, | |
117 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None | |
118 ); | |
119 } | |
120 | |
121 class NumberFormatException : IllegalArgumentException { | |
122 this( char[] e ){ | |
123 super(e); | |
124 } | |
125 this( TracedException e ){ | |
126 super(e.toString); | |
127 } | |
128 } | |
129 | |
130 | |
131 | |
132 | |
133 | |
134 |