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