Mercurial > projects > dwt-win
annotate dwt/dwthelper/utils.d @ 98:ecba636b634e
package dwt/ole
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 09 Feb 2008 03:36:27 +0100 |
parents | 2e6eb5bd2c16 |
children | 6bfa783ac0b4 |
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 |
98 | 9 public import tango.core.Exception : IllegalArgumentException, IOException; |
97 | 10 |
0 | 11 import tango.io.Stdout; |
15 | 12 import tango.stdc.stringz; |
13 import tango.text.Util; | |
0 | 14 import tango.text.Unicode; |
15 | 15 import tango.text.convert.Utf; |
0 | 16 import tango.stdc.stdlib : exit; |
17 | |
18 void implMissing( char[] file, uint line ){ | |
19 Stderr.formatln( "implementation missing in file {} line {}", file, line ); | |
20 Stderr.formatln( "exiting ..." ); | |
21 exit(1); | |
22 } | |
23 | |
24 abstract class ArrayWrapper{ | |
25 } | |
33 | 26 abstract class ValueWrapper{ |
27 } | |
0 | 28 |
29 class ArrayWrapperT(T) : ArrayWrapper { | |
30 public T[] array; | |
31 public this( T[] data ){ | |
32 array = data; | |
33 } | |
34 } | |
35 | |
33 | 36 class ValueWrapperT(T) : ValueWrapper { |
37 public T value; | |
38 public this( T data ){ | |
39 value = data; | |
40 } | |
41 } | |
42 | |
43 alias ValueWrapperT!(bool) ValueWrapperBool; | |
98 | 44 alias ValueWrapperT!(int) ValueWrapperInt; |
0 | 45 alias ArrayWrapperT!(byte) ArrayWrapperByte; |
46 alias ArrayWrapperT!(int) ArrayWrapperInt; | |
47 alias ArrayWrapperT!(Object) ArrayWrapperObject; | |
48 alias ArrayWrapperT!(char) ArrayWrapperString; | |
49 alias ArrayWrapperT!(char[]) ArrayWrapperString2; | |
50 | |
51 dchar getFirstCodepoint( char[] str ){ | |
52 foreach( dchar d; str ){ | |
53 return d; | |
54 } | |
55 } | |
56 dchar CharacterToLower( dchar c ){ | |
57 dchar[] r = tango.text.Unicode.toLower( [c] ); | |
58 return r[0]; | |
59 } | |
60 dchar CharacterToUpper( dchar c ){ | |
61 dchar[] r = tango.text.Unicode.toUpper( [c] ); | |
62 return r[0]; | |
63 } | |
52 | 64 bool CharacterIsWhitespace( dchar c ){ |
65 return tango.text.Unicode.isWhitespace( c ); | |
66 } | |
65 | 67 bool CharacterIsDigit( dchar c ){ |
68 return tango.text.Unicode.isDigit( c ); | |
69 } | |
0 | 70 |
15 | 71 public int indexOf( char[] str, char searched ){ |
72 int res = tango.text.Util.locate( str, searched ); | |
73 if( res is str.length ) res = -1; | |
74 return res; | |
75 } | |
76 | |
77 public int indexOf( char[] str, char searched, int startpos ){ | |
78 int res = tango.text.Util.locate( str, searched, startpos ); | |
79 if( res is str.length ) res = -1; | |
80 return res; | |
81 } | |
82 | |
65 | 83 public int indexOf(char[] str, char[] ch){ |
84 return indexOf( str, ch, 0 ); | |
85 } | |
86 | |
15 | 87 public int indexOf(char[] str, char[] ch, int start){ |
88 int res = tango.text.Util.locatePattern( str, ch, start ); | |
89 if( res is str.length ) res = -1; | |
90 return res; | |
91 } | |
92 | |
84
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
79
diff
changeset
|
93 public char[] replace( char[] str, char from, char to ){ |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
79
diff
changeset
|
94 return tango.text.Util.replace( str.dup, from, to ); |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
79
diff
changeset
|
95 } |
00a333240696
FileDialog, sync dwthelper with dwt-linux, some TCHAR issues
Frank Benoit <benoit@tionex.de>
parents:
79
diff
changeset
|
96 |
15 | 97 public char[] substring( char[] str, int start ){ |
98 return str[ start .. $ ].dup; | |
99 } | |
100 | |
101 public char[] substring( char[] str, int start, int end ){ | |
102 return str[ start .. end ].dup; | |
103 } | |
104 | |
105 public wchar[] substring( wchar[] str, int start ){ | |
106 return str[ start .. $ ].dup; | |
107 } | |
108 | |
109 public wchar[] substring( wchar[] str, int start, int end ){ | |
110 return str[ start .. end ].dup; | |
111 } | |
112 | |
113 public char charAt( char[] str, int pos ){ | |
114 return str[ pos ]; | |
115 } | |
116 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
117 public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
23 | 118 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
|
119 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
120 |
28 | 121 public wchar[] toCharArray( char[] str ){ |
30 | 122 return toString16( str ); |
28 | 123 } |
124 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
125 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
|
126 if( src.length < pattern.length ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
127 return false; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
128 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
129 return src[ $-pattern.length .. $ ] == pattern; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
130 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
131 |
98 | 132 public bool startsWith( char[] src, char[] pattern ){ |
133 if( src.length < pattern.length ){ | |
134 return false; | |
135 } | |
136 return src[ 0 .. pattern.length ] == pattern; | |
137 } | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
138 public char[] toLowerCase( char[] src ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
139 return tango.text.Unicode.toLower( src ); |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
140 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
141 |
15 | 142 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
|
143 return tango.text.convert.Integer.toString( |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
144 value, |
15 | 145 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
146 radix is 8 ? tango.text.convert.Integer.Style.Octal : | |
147 radix is 16 ? tango.text.convert.Integer.Style.Hex : | |
148 tango.text.convert.Integer.Style.Signed, | |
149 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None | |
150 ); | |
151 } | |
152 | |
153 class NumberFormatException : IllegalArgumentException { | |
154 this( char[] e ){ | |
155 super(e); | |
156 } | |
57
41dbc4d9faab
Update to tango trunk -r3152. Thanks DavidLeon for the adjustment of TracedException to Exception and creating the patch.
Frank Benoit <benoit@tionex.de>
parents:
52
diff
changeset
|
157 this( Exception e ){ |
15 | 158 super(e.toString); |
159 } | |
160 } | |
161 | |
79 | 162 private struct GCStats { |
40 | 163 size_t poolsize; // total size of pool |
164 size_t usedsize; // bytes allocated | |
165 size_t freeblocks; // number of blocks marked FREE | |
166 size_t freelistsize; // total of memory on free lists | |
167 size_t pageblocks; // number of blocks marked PAGE | |
168 } | |
79 | 169 private extern(C) GCStats gc_stats(); |
170 | |
40 | 171 size_t RuntimeTotalMemory(){ |
172 GCStats s = gc_stats(); | |
173 return s.poolsize; | |
174 } | |
15 | 175 |
176 | |
177 | |
178 |