Mercurial > projects > dwt-win
annotate dwt/dwthelper/utils.d @ 78:b00303c762ac
successfully linked
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 05 Feb 2008 20:28:19 +0100 |
parents | 66203354c9d3 |
children | 67d24430822a |
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 | |
91 public char[] substring( char[] str, int start ){ | |
92 return str[ start .. $ ].dup; | |
93 } | |
94 | |
95 public char[] substring( char[] str, int start, int end ){ | |
96 return str[ start .. end ].dup; | |
97 } | |
98 | |
99 public wchar[] substring( wchar[] str, int start ){ | |
100 return str[ start .. $ ].dup; | |
101 } | |
102 | |
103 public wchar[] substring( wchar[] str, int start, int end ){ | |
104 return str[ start .. end ].dup; | |
105 } | |
106 | |
107 public char charAt( char[] str, int pos ){ | |
108 return str[ pos ]; | |
109 } | |
110 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
111 public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
23 | 112 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
|
113 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
114 |
28 | 115 public wchar[] toCharArray( char[] str ){ |
30 | 116 return toString16( str ); |
28 | 117 } |
118 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
119 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
|
120 if( src.length < pattern.length ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
121 return false; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
122 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
123 return src[ $-pattern.length .. $ ] == pattern; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
124 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
125 |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
126 public char[] toLowerCase( char[] src ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
127 return tango.text.Unicode.toLower( src ); |
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 |
15 | 130 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
|
131 return tango.text.convert.Integer.toString( |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
132 value, |
15 | 133 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
134 radix is 8 ? tango.text.convert.Integer.Style.Octal : | |
135 radix is 16 ? tango.text.convert.Integer.Style.Hex : | |
136 tango.text.convert.Integer.Style.Signed, | |
137 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None | |
138 ); | |
139 } | |
140 | |
141 class NumberFormatException : IllegalArgumentException { | |
142 this( char[] e ){ | |
143 super(e); | |
144 } | |
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
|
145 this( Exception e ){ |
15 | 146 super(e.toString); |
147 } | |
148 } | |
149 | |
40 | 150 struct GCStats { |
151 size_t poolsize; // total size of pool | |
152 size_t usedsize; // bytes allocated | |
153 size_t freeblocks; // number of blocks marked FREE | |
154 size_t freelistsize; // total of memory on free lists | |
155 size_t pageblocks; // number of blocks marked PAGE | |
156 } | |
78 | 157 extern(C) GCStats gc_stats(); |
40 | 158 size_t RuntimeTotalMemory(){ |
159 GCStats s = gc_stats(); | |
160 return s.poolsize; | |
161 } | |
15 | 162 |
78 | 163 } |
15 | 164 |
165 | |
166 |