Mercurial > projects > dwt-win
view dwt/dwthelper/utils.d @ 22:5f2e72114476
Image in work, this revision does not compile
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Sat, 26 Jan 2008 19:05:32 +0100 |
parents | 1bea9f0c6f63 |
children | f5482da87ed8 |
line wrap: on
line source
/** * Authors: Frank Benoit <keinfarbton@googlemail.com> */ module dwt.dwthelper.utils; public import dwt.dwthelper.System; public import Math = tango.math.Math; import tango.io.Stdout; import tango.stdc.stringz; import tango.text.Util; import tango.text.Unicode; import tango.text.convert.Utf; import tango.core.Exception; import tango.stdc.stdlib : exit; void implMissing( char[] file, uint line ){ Stderr.formatln( "implementation missing in file {} line {}", file, line ); Stderr.formatln( "exiting ..." ); exit(1); } abstract class ArrayWrapper{ } class ArrayWrapperT(T) : ArrayWrapper { public T[] array; public this( T[] data ){ array = data; } } alias ArrayWrapperT!(byte) ArrayWrapperByte; alias ArrayWrapperT!(int) ArrayWrapperInt; alias ArrayWrapperT!(Object) ArrayWrapperObject; alias ArrayWrapperT!(char) ArrayWrapperString; alias ArrayWrapperT!(char[]) ArrayWrapperString2; dchar getFirstCodepoint( char[] str ){ foreach( dchar d; str ){ return d; } } dchar CharacterToLower( dchar c ){ dchar[] r = tango.text.Unicode.toLower( [c] ); return r[0]; } dchar CharacterToUpper( dchar c ){ dchar[] r = tango.text.Unicode.toUpper( [c] ); return r[0]; } public int indexOf( char[] 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 ){ 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, int start){ int res = tango.text.Util.locatePattern( str, ch, start ); if( res is str.length ) res = -1; return res; } public char[] substring( char[] str, int start ){ return str[ start .. $ ].dup; } public char[] substring( char[] str, int start, int end ){ return str[ start .. end ].dup; } public wchar[] substring( wchar[] str, int start ){ return str[ start .. $ ].dup; } public wchar[] substring( wchar[] str, int start, int end ){ return str[ start .. end ].dup; } public char charAt( char[] str, int pos ){ return str[ pos ]; } public void getChars( char[] src, int srcBegin, int srcEnd, char[] dst, int dstBegin){ dst[ dstBegin .. dstBegin + srcEnd - srcBegin ] = str[ srcBegin .. srcEnd ]; } public bool endsWith( char[] src, char[] pattern ){ if( src.length < pattern.length ){ return false; } return src[ $-pattern.length .. $ ] == pattern; } public char[] toLowerCase( char[] src ){ return tango.text.Unicode.toLower( src ); } static char[] 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 : radix is 8 ? tango.text.convert.Integer.Style.Octal : radix is 16 ? tango.text.convert.Integer.Style.Hex : tango.text.convert.Integer.Style.Signed, prefix ? tango.text.convert.Integer.Flags.Prefix : tango.text.convert.Integer.Flags.None ); } class NumberFormatException : IllegalArgumentException { this( char[] e ){ super(e); } this( TracedException e ){ super(e.toString); } }