Mercurial > projects > dwt-win
diff dwt/dwthelper/utils.d @ 212:ab60f3309436
reverted the char[] to String and use the an alias.
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 05 May 2008 00:12:38 +0200 |
parents | cca980503056 |
children | 679fb4a215dc |
line wrap: on
line diff
--- a/dwt/dwthelper/utils.d Sat Apr 26 10:01:48 2008 +0200 +++ b/dwt/dwthelper/utils.d Mon May 05 00:12:38 2008 +0200 @@ -35,7 +35,7 @@ alias char[] String; alias tango.text.Text.Text!(char) StringBuffer; -void implMissing( char[] file, uint line ){ +void implMissing( String file, uint line ){ Stderr.formatln( "implementation missing in file {} line {}", file, line ); Stderr.formatln( "exiting ..." ); exit(1); @@ -94,7 +94,7 @@ public bool booleanValue(){ return value; } - public static Boolean valueOf( char[] s ){ + public static Boolean valueOf( String s ){ if( s == "yes" || s == "true" ){ return TRUE; } @@ -109,7 +109,7 @@ class Byte : ValueWrapperT!(byte) { - public static byte parseByte( char[] s ){ + public static byte parseByte( String s ){ try{ int res = tango.text.convert.Integer.parse( s ); if( res < byte.min || res > byte.max ){ @@ -138,11 +138,11 @@ super( value ); } - public this ( char[] s ){ + public this ( String s ){ super(parseInt(s)); } - public static char[] toString( int i, int radix ){ + public static String toString( int i, int radix ){ switch( radix ){ case 2: return toBinaryString(i); @@ -158,23 +158,23 @@ } } - public static char[] toHexString( int i ){ + public static String toHexString( int i ){ return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Hex ); } - public static char[] toOctalString( int i ){ + public static String toOctalString( int i ){ return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Octal ); } - public static char[] toBinaryString( int i ){ + public static String toBinaryString( int i ){ return tango.text.convert.Integer.toString(i, tango.text.convert.Integer.Style.Binary ); } - public static char[] toString( int i ){ + public static String toString( int i ){ return tango.text.convert.Integer.toString(i); } - public static int parseInt( char[] s, int radix ){ + public static int parseInt( String s, int radix ){ try{ return tango.text.convert.Integer.parse( s, cast(uint)radix ); } @@ -183,7 +183,7 @@ } } - public static int parseInt( char[] s ){ + public static int parseInt( String s ){ try{ return tango.text.convert.Integer.parse( s ); } @@ -192,12 +192,12 @@ } } - public static Integer valueOf( char[] s, int radix ){ + public static Integer valueOf( String s, int radix ){ implMissing( __FILE__, __LINE__ ); return null; } - public static Integer valueOf( char[] s ){ + public static Integer valueOf( String s ){ return valueOf( parseInt(s)); } @@ -233,7 +233,7 @@ return intValue(); } - public override char[] toString(){ + public override String toString(){ return tango.text.convert.Integer.toString( value ); } } @@ -243,14 +243,14 @@ this( double value ){ super(value); } - this( char[] str ){ + this( String str ){ implMissing( __FILE__, __LINE__ ); super(0.0); } public double doubleValue(){ return value; } - public static char[] toString( double value ){ + public static String toString( double value ){ implMissing( __FILE__, __LINE__ ); return null; } @@ -268,18 +268,18 @@ this( float value ){ super(value); } - this( char[] str ){ + this( String str ){ implMissing( __FILE__, __LINE__ ); super(0.0); } public float floatValue(){ return value; } - public static char[] toString( float value ){ + public static String toString( float value ){ implMissing( __FILE__, __LINE__ ); return null; } - public static float parseFloat( char[] s ){ + public static float parseFloat( String s ){ try{ return tango.text.convert.Float.toFloat( s ); } @@ -293,18 +293,18 @@ this( long value ){ super(value); } - this( char[] str ){ + this( String str ){ implMissing( __FILE__, __LINE__ ); super(0); } public long longValue(){ return value; } - public static long parseLong(char[] s){ + public static long parseLong(String s){ implMissing( __FILE__, __LINE__ ); return 0; } - public static char[] toString( double value ){ + public static String toString( double value ){ implMissing( __FILE__, __LINE__ ); return null; } @@ -318,7 +318,7 @@ alias ArrayWrapperT!(int) ArrayWrapperInt; alias ArrayWrapperT!(Object) ArrayWrapperObject; alias ArrayWrapperT!(char) ArrayWrapperString; -alias ArrayWrapperT!(char[]) ArrayWrapperString2; +alias ArrayWrapperT!(String) ArrayWrapperString2; Object[] StringArrayToObjectArray( String[] strs ){ Object[] res = new Object[strs.length]; @@ -327,7 +327,7 @@ } return res; } -int codepointIndexToIndex( char[] str, int cpIndex ){ +int codepointIndexToIndex( String str, int cpIndex ){ int cps = cpIndex; int res = 0; while( cps > 0 ){ @@ -347,7 +347,7 @@ } return res; } -int indexToCodepointIndex( char[] str, int index ){ +int indexToCodepointIndex( String str, int index ){ int i = 0; int res = 0; while( i < index ){ @@ -368,7 +368,7 @@ return res; } -char[] firstCodePointStr( char[] str, out int consumed ){ +String firstCodePointStr( String str, out int consumed ){ dchar[1] buf; uint ate; dchar[] res = str.toString32( buf, &ate ); @@ -376,11 +376,11 @@ return str[ 0 .. ate ]; } -dchar firstCodePoint( char[] str ){ +dchar firstCodePoint( String str ){ int dummy; return firstCodePoint( str, dummy ); } -dchar firstCodePoint( char[] str, out int consumed ){ +dchar firstCodePoint( String str, out int consumed ){ dchar[1] buf; uint ate; dchar[] res = str.toString32( buf, &ate ); @@ -393,13 +393,13 @@ return res[0]; } -char[] dcharToString( dchar key ){ +String dcharToString( dchar key ){ dchar[1] buf; buf[0] = key; return tango.text.convert.Utf.toString( buf ); } -int codepointCount( char[] str ){ +int codepointCount( String str ){ scope dchar[] buf = new dchar[]( str.length ); uint ate; dchar[] res = tango.text.convert.Utf.toString32( str, buf, &ate ); @@ -410,7 +410,7 @@ alias tango.text.convert.Utf.toString16 toString16; alias tango.text.convert.Utf.toString toString; -int getRelativeCodePointOffset( char[] str, int startIndex, int searchRelCp ){ +int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ int ignore; int i = startIndex; if( searchRelCp > 0 ){ @@ -462,13 +462,13 @@ } return i - startIndex; } -dchar getRelativeCodePoint( char[] str, int startIndex, int searchRelCp, out int relIndex ){ +dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp ); int ignore; return firstCodePoint( str[ startIndex+relIndex .. $ ], ignore ); } -int utf8AdjustOffset( char[] str, int offset ){ +int utf8AdjustOffset( String str, int offset ){ if( str.length <= offset || offset <= 0 ){ return offset; } @@ -481,11 +481,11 @@ bool CharacterIsDefined( dchar ch ){ return (ch in tango.text.UnicodeData.unicodeData) !is null; } -dchar CharacterFirstToLower( char[] str ){ +dchar CharacterFirstToLower( String str ){ int consumed; return CharacterFirstToLower( str, consumed ); } -dchar CharacterFirstToLower( char[] str, out int consumed ){ +dchar CharacterFirstToLower( String str, out int consumed ){ dchar[1] buf; buf[0] = firstCodePoint( str, consumed ); dchar[] r = tango.text.Unicode.toLower( buf ); @@ -509,58 +509,58 @@ bool CharacterIsLetter( dchar c ){ return tango.text.Unicode.isLetter( c ); } -public char[] toUpperCase( char[] str ){ +public String toUpperCase( String str ){ return tango.text.Unicode.toUpper( str ); } -public int indexOf( char[] str, char searched ){ +public int indexOf( String str, char searched ){ int res = tango.text.Util.locate( str, searched ); if( res is str.length ) res = -1; return res; } -public int indexOf( char[] str, char searched, int startpos ){ +public int indexOf( String str, char searched, int startpos ){ int res = tango.text.Util.locate( str, searched, startpos ); if( res is str.length ) res = -1; return res; } -public int indexOf(char[] str, char[] ch){ +public int indexOf(String str, String ch){ return indexOf( str, ch, 0 ); } -public int indexOf(char[] str, char[] ch, int start){ +public int indexOf(String str, String ch, int start){ int res = tango.text.Util.locatePattern( str, ch, start ); if( res is str.length ) res = -1; return res; } -public int lastIndexOf(char[] str, char ch){ +public int lastIndexOf(String str, char ch){ return lastIndexOf( str, ch, str.length ); } -public int lastIndexOf(char[] str, char ch, int formIndex){ +public int lastIndexOf(String str, char ch, int formIndex){ int res = tango.text.Util.locatePrior( str, ch, formIndex ); if( res is str.length ) res = -1; return res; } -public int lastIndexOf(char[] str, char[] ch ){ +public int lastIndexOf(String str, String ch ){ return lastIndexOf( str, ch, str.length ); } -public int lastIndexOf(char[] str, char[] ch, int start ){ +public int lastIndexOf(String str, String ch, int start ){ int res = tango.text.Util.locatePatternPrior( str, ch, start ); if( res is str.length ) res = -1; return res; } -public char[] replace( char[] str, char from, char to ){ +public String replace( String str, char from, char to ){ return tango.text.Util.replace( str.dup, from, to ); } -public char[] substring( char[] str, int start ){ +public String substring( String str, int start ){ return str[ start .. $ ].dup; } -public char[] substring( char[] str, int start, int end ){ +public String substring( String str, int start, int end ){ return str[ start .. end ].dup; } @@ -572,66 +572,66 @@ return str[ start .. end ].dup; } -public char charAt( char[] str, int pos ){ +public char charAt( String str, int pos ){ return str[ pos ]; } -public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ +public void getChars( String src, int srcBegin, int srcEnd, String dst, int dstBegin){ dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = src[ srcBegin .. srcEnd ]; } -public wchar[] toCharArray( char[] str ){ +public wchar[] toCharArray( String str ){ return toString16( str ); } -public bool endsWith( char[] src, char[] pattern ){ +public bool endsWith( String src, String pattern ){ if( src.length < pattern.length ){ return false; } return src[ $-pattern.length .. $ ] == pattern; } -public bool equals( char[] src, char[] other ){ +public bool equals( String src, String other ){ return src == other; } -public bool equalsIgnoreCase( char[] src, char[] other ){ +public bool equalsIgnoreCase( String src, String other ){ return tango.text.Unicode.toFold(src) == tango.text.Unicode.toFold(other); } -public bool startsWith( char[] src, char[] pattern ){ +public bool startsWith( String src, String pattern ){ if( src.length < pattern.length ){ return false; } return src[ 0 .. pattern.length ] == pattern; } -public char[] toLowerCase( char[] src ){ +public String toLowerCase( String src ){ return tango.text.Unicode.toLower( src ); } -public hash_t toHash( char[] src ){ - return typeid(char[]).getHash(&src); +public hash_t toHash( String src ){ + return typeid(String).getHash(&src); } -public char[] trim( char[] str ){ +public String trim( String str ){ return tango.text.Util.trim( str ).dup; } -public char[] intern( char[] str ){ +public String intern( String str ){ return str; } -public char* toStringzValidPtr( char[] src ){ +public char* toStringzValidPtr( String src ){ if( src ){ return src.toStringz(); } else{ - static const char[] nullPtr = "\0"; + static const String nullPtr = "\0"; return nullPtr.ptr; } } -static char[] toHex(uint value, bool prefix = true, int radix = 8){ +static String toHex(uint value, bool prefix = true, int radix = 8){ return tango.text.convert.Integer.toString( value, radix is 10 ? tango.text.convert.Integer.Style.Signed : @@ -643,7 +643,7 @@ } class RuntimeException : Exception { - this( char[] e = null){ + this( String e = null){ super(e); } this( Exception e ){ @@ -656,13 +656,13 @@ } class IndexOutOfBoundsException : Exception { - this( char[] e = null){ + this( String e = null){ super(e); } } class UnsupportedOperationException : RuntimeException { - this( char[] e = null){ + this( String e = null){ super(e); } this( Exception e ){ @@ -670,7 +670,7 @@ } } class NumberFormatException : IllegalArgumentException { - this( char[] e ){ + this( String e ){ super(e); } this( Exception e ){ @@ -678,7 +678,7 @@ } } class NullPointerException : Exception { - this( char[] e = null ){ + this( String e = null ){ super(e); } this( Exception e ){ @@ -686,7 +686,7 @@ } } class IllegalStateException : Exception { - this( char[] e = null ){ + this( String e = null ){ super(e); } this( Exception e ){ @@ -694,7 +694,7 @@ } } class InterruptedException : Exception { - this( char[] e = null ){ + this( String e = null ){ super(e); } this( Exception e ){ @@ -703,7 +703,7 @@ } class InvocationTargetException : Exception { Exception cause; - this( Exception e = null, char[] msg = null ){ + this( Exception e = null, String msg = null ){ super(msg); cause = e; } @@ -714,16 +714,16 @@ } } class MissingResourceException : Exception { - char[] classname; - char[] key; - this( char[] msg, char[] classname, char[] key ){ + String classname; + String key; + this( String msg, String classname, String key ){ super(msg); this.classname = classname; this.key = key; } } class ParseException : Exception { - this( char[] e = null ){ + this( String e = null ){ super(e); } } @@ -753,7 +753,7 @@ return source; } - public override char[] toString() { + public override String toString() { return this.classinfo.name ~ "[source=" ~ source.toString() ~ "]"; } } @@ -831,23 +831,23 @@ } } -char[] stringcast( Object o ){ +String stringcast( Object o ){ if( auto str = cast(ArrayWrapperString) o ){ return str.array; } return null; } -char[][] stringcast( Object[] objs ){ - char[][] res = new char[][](objs.length); +String[] stringcast( Object[] objs ){ + String[] res = new String[](objs.length); foreach( idx, obj; objs ){ res[idx] = stringcast(obj); } return res; } -ArrayWrapperString stringcast( char[] str ){ +ArrayWrapperString stringcast( String str ){ return new ArrayWrapperString( str ); } -ArrayWrapperString[] stringcast( char[][] strs ){ +ArrayWrapperString[] stringcast( String[] strs ){ ArrayWrapperString[] res = new ArrayWrapperString[ strs.length ]; foreach( idx, str; strs ){ res[idx] = stringcast(str); @@ -936,7 +936,7 @@ return res; } -void PrintStackTrace( int deepth = 100, char[] prefix = "trc" ){ +void PrintStackTrace( int deepth = 100, String prefix = "trc" ){ auto e = new Exception( null ); int idx = 0; const start = 3; @@ -950,9 +950,9 @@ struct ImportData{ void[] data; - char[] name; + String name; - public static ImportData opCall( void[] data, char[] name ){ + public static ImportData opCall( void[] data, String name ){ ImportData res; res.data = data; res.name = name; @@ -960,6 +960,6 @@ } } -template getImportData(char[] name ){ +template getImportData(String name ){ const ImportData getImportData = ImportData( import(name), name ); -} \ No newline at end of file +}