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