15
|
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 }
|
|
25
|
|
26 class ArrayWrapperT(T) : ArrayWrapper {
|
|
27 public T[] array;
|
|
28 public this( T[] data ){
|
|
29 array = data;
|
|
30 }
|
|
31 }
|
|
32
|
|
33 alias ArrayWrapperT!(byte) ArrayWrapperByte;
|
|
34 alias ArrayWrapperT!(int) ArrayWrapperInt;
|
|
35 alias ArrayWrapperT!(Object) ArrayWrapperObject;
|
|
36 alias ArrayWrapperT!(char) ArrayWrapperString;
|
|
37 alias ArrayWrapperT!(char[]) ArrayWrapperString2;
|
|
38
|
|
39 dchar getFirstCodepoint( char[] str ){
|
|
40 foreach( dchar d; str ){
|
|
41 return d;
|
|
42 }
|
|
43 }
|
|
44 dchar CharacterToLower( dchar c ){
|
|
45 dchar[] r = tango.text.Unicode.toLower( [c] );
|
|
46 return r[0];
|
|
47 }
|
|
48 dchar CharacterToUpper( dchar c ){
|
|
49 dchar[] r = tango.text.Unicode.toUpper( [c] );
|
|
50 return r[0];
|
|
51 }
|
|
52
|
15
|
53 public int indexOf( char[] str, char searched ){
|
|
54 int res = tango.text.Util.locate( str, searched );
|
|
55 if( res is str.length ) res = -1;
|
|
56 return res;
|
|
57 }
|
|
58
|
|
59 public int indexOf( char[] str, char searched, int startpos ){
|
|
60 int res = tango.text.Util.locate( str, searched, startpos );
|
|
61 if( res is str.length ) res = -1;
|
|
62 return res;
|
|
63 }
|
|
64
|
|
65 public int indexOf(char[] str, char[] ch, int start){
|
|
66 int res = tango.text.Util.locatePattern( str, ch, start );
|
|
67 if( res is str.length ) res = -1;
|
|
68 return res;
|
|
69 }
|
|
70
|
|
71 public char[] substring( char[] str, int start ){
|
|
72 return str[ start .. $ ].dup;
|
|
73 }
|
|
74
|
|
75 public char[] substring( char[] str, int start, int end ){
|
|
76 return str[ start .. end ].dup;
|
|
77 }
|
|
78
|
|
79 public wchar[] substring( wchar[] str, int start ){
|
|
80 return str[ start .. $ ].dup;
|
|
81 }
|
|
82
|
|
83 public wchar[] substring( wchar[] str, int start, int end ){
|
|
84 return str[ start .. end ].dup;
|
|
85 }
|
|
86
|
|
87 public char charAt( char[] str, int pos ){
|
|
88 return str[ pos ];
|
|
89 }
|
|
90
|
|
91 static char[] toHex(uint value, bool prefix = true, int radix = 8){
|
|
92 return tango.text.convert.Integer.toString(
|
|
93 value,
|
|
94 radix is 10 ? tango.text.convert.Integer.Style.Signed :
|
|
95 radix is 8 ? tango.text.convert.Integer.Style.Octal :
|
|
96 radix is 16 ? tango.text.convert.Integer.Style.Hex :
|
|
97 tango.text.convert.Integer.Style.Signed,
|
|
98 prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None
|
|
99 );
|
|
100 }
|
|
101
|
|
102 class NumberFormatException : IllegalArgumentException {
|
|
103 this( char[] e ){
|
|
104 super(e);
|
|
105 }
|
|
106 this( TracedException e ){
|
|
107 super(e.toString);
|
|
108 }
|
|
109 }
|
|
110
|
|
111
|
|
112
|
|
113
|
|
114
|
|
115
|