Mercurial > projects > dwt-win
annotate dwt/dwthelper/utils.d @ 57:41dbc4d9faab
Update to tango trunk -r3152. Thanks DavidLeon for the adjustment of TracedException to Exception and creating the patch.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 04 Feb 2008 12:46:24 +0100 |
parents | 0553f4e8ed93 |
children | 66203354c9d3 |
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 } | |
0 | 65 |
15 | 66 public int indexOf( char[] str, char searched ){ |
67 int res = tango.text.Util.locate( str, searched ); | |
68 if( res is str.length ) res = -1; | |
69 return res; | |
70 } | |
71 | |
72 public int indexOf( char[] str, char searched, int startpos ){ | |
73 int res = tango.text.Util.locate( str, searched, startpos ); | |
74 if( res is str.length ) res = -1; | |
75 return res; | |
76 } | |
77 | |
78 public int indexOf(char[] str, char[] ch, int start){ | |
79 int res = tango.text.Util.locatePattern( str, ch, start ); | |
80 if( res is str.length ) res = -1; | |
81 return res; | |
82 } | |
83 | |
84 public char[] substring( char[] str, int start ){ | |
85 return str[ start .. $ ].dup; | |
86 } | |
87 | |
88 public char[] substring( char[] str, int start, int end ){ | |
89 return str[ start .. end ].dup; | |
90 } | |
91 | |
92 public wchar[] substring( wchar[] str, int start ){ | |
93 return str[ start .. $ ].dup; | |
94 } | |
95 | |
96 public wchar[] substring( wchar[] str, int start, int end ){ | |
97 return str[ start .. end ].dup; | |
98 } | |
99 | |
100 public char charAt( char[] str, int pos ){ | |
101 return str[ pos ]; | |
102 } | |
103 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
104 public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ |
23 | 105 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
|
106 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
107 |
28 | 108 public wchar[] toCharArray( char[] str ){ |
30 | 109 return toString16( str ); |
28 | 110 } |
111 | |
22
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
112 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
|
113 if( src.length < pattern.length ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
114 return false; |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
115 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
116 return src[ $-pattern.length .. $ ] == pattern; |
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 |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
119 public char[] toLowerCase( char[] src ){ |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
120 return tango.text.Unicode.toLower( src ); |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
121 } |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
122 |
15 | 123 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
|
124 return tango.text.convert.Integer.toString( |
5f2e72114476
Image in work, this revision does not compile
Frank Benoit <benoit@tionex.de>
parents:
15
diff
changeset
|
125 value, |
15 | 126 radix is 10 ? tango.text.convert.Integer.Style.Signed : |
127 radix is 8 ? tango.text.convert.Integer.Style.Octal : | |
128 radix is 16 ? tango.text.convert.Integer.Style.Hex : | |
129 tango.text.convert.Integer.Style.Signed, | |
130 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None | |
131 ); | |
132 } | |
133 | |
134 class NumberFormatException : IllegalArgumentException { | |
135 this( char[] e ){ | |
136 super(e); | |
137 } | |
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
|
138 this( Exception e ){ |
15 | 139 super(e.toString); |
140 } | |
141 } | |
142 | |
40 | 143 struct GCStats { |
144 size_t poolsize; // total size of pool | |
145 size_t usedsize; // bytes allocated | |
146 size_t freeblocks; // number of blocks marked FREE | |
147 size_t freelistsize; // total of memory on free lists | |
148 size_t pageblocks; // number of blocks marked PAGE | |
149 } | |
150 | |
151 extern(System) GCStats gc_stats(); | |
152 | |
153 size_t RuntimeTotalMemory(){ | |
154 GCStats s = gc_stats(); | |
155 return s.poolsize; | |
156 } | |
15 | 157 |
158 | |
159 | |
160 |