Mercurial > projects > dwt-linux
changeset 307:9995e4a9d2ee
sync with dwt-win
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Thu, 21 Aug 2008 17:34:04 +0200 |
parents | 9764f08379f2 |
children | dc2ae028d2d8 |
files | dwt/dwthelper/InflaterInputStream.d dwt/dwthelper/utils.d |
diffstat | 2 files changed, 76 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/dwt/dwthelper/InflaterInputStream.d Sat Aug 16 23:12:10 2008 -0700 +++ b/dwt/dwthelper/InflaterInputStream.d Thu Aug 21 17:34:04 2008 +0200 @@ -7,6 +7,11 @@ import dwt.dwthelper.utils; import tango.io.Stdout; import tango.io.compress.ZlibStream; +version(Windows){ + version(build){ + pragma(link,"zlib"); + } +} import tango.io.Conduit; class InputStreamWrapper : tango.io.model.IConduit.InputStream { @@ -21,7 +26,6 @@ int res = istr.read( cast(byte[])dst ); return res; } - void[] load (void[] dst = null) { return Conduit.load (this, dst); }
--- a/dwt/dwthelper/utils.d Sat Aug 16 23:12:10 2008 -0700 +++ b/dwt/dwthelper/utils.d Thu Aug 21 17:34:04 2008 +0200 @@ -197,7 +197,7 @@ public static int parseInt( String s, int radix ){ try{ - return tango.text.convert.Integer.parse( s, cast(uint)radix ); + return tango.text.convert.Integer.toLong( s, radix ); } catch( IllegalArgumentException e ){ throw new NumberFormatException( e ); @@ -206,7 +206,7 @@ public static int parseInt( String s ){ try{ - return tango.text.convert.Integer.parse( s ); + return tango.text.convert.Integer.toLong( s ); } catch( IllegalArgumentException e ){ throw new NumberFormatException( e ); @@ -372,6 +372,10 @@ } return res; } + +/++ + + + +/ int indexToCodepointIndex( String str, int index ){ if( index < 0 ) return index; int i = 0; @@ -397,6 +401,9 @@ return res; } +/++ + + Get that String, that contains the next codepoint of a String. + +/ String firstCodePointStr( String str, out int consumed ){ dchar[1] buf; uint ate; @@ -405,6 +412,12 @@ return str[ 0 .. ate ]; } +/++ + + Get first codepoint of a String. If an offset is needed, simply use a slice: + + --- + + dchar res = str[ offset .. $ ].firstCodePoint(); + + --- + +/ dchar firstCodePoint( String str ){ int dummy; return firstCodePoint( str, dummy ); @@ -421,6 +434,18 @@ assert( res.length is 1 ); return res[0]; } +dchar firstCodePoint( wchar[] str, out int consumed ){ + dchar[1] buf; + uint ate; + dchar[] res = str.toString32( buf, &ate ); + consumed = ate; + if( ate is 0 || res.length is 0 ){ + Trace.formatln( "dwthelper.utils {}: str.length={} str={:X2}", __LINE__, str.length, cast(ubyte[])str ); + } + assert( ate > 0 ); + assert( res.length is 1 ); + return res[0]; +} String dcharToString( dchar key ){ dchar[1] buf; @@ -440,6 +465,9 @@ alias tango.text.convert.Utf.toString toString; int getRelativeCodePointOffset( String str, int startIndex, int searchRelCp ){ + return getAbsoluteCodePointOffset( str, startIndex, searchRelCp ) - startIndex; +} +int getAbsoluteCodePointOffset( String str, int startIndex, int searchRelCp ){ int ignore; int i = startIndex; if( searchRelCp > 0 ){ @@ -483,7 +511,7 @@ do{ i--; if( i < 0 ){ - return -1; + return startIndex-1; //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); } @@ -491,7 +519,46 @@ searchRelCp++; } } - return i - startIndex; + return i; +} +int getAbsoluteCodePointOffset( wchar[] str, int startIndex, int searchRelCp ){ + int ignore; + int i = startIndex; + if( searchRelCp > 0 ){ + while( searchRelCp !is 0 ){ + + if( ( i < str.length ) + && ( str[i] & 0xD800 ) !is 0xD800 ) + { + i+=1; + } + else if( ( i+1 < str.length ) + && (( str[i+1] & 0xDC00 ) is 0xDC00 ) + && (( str[i ] & 0xDC00 ) is 0xD800 )) + { + i+=2; + } + else{ + Trace.formatln( "invalid utf8 characters: {:X2}", cast(ubyte[]) str ); + tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); + } + searchRelCp--; + } + } + else if( searchRelCp < 0 ){ + while( searchRelCp !is 0 ){ + do{ + i--; + if( i < 0 ){ + return startIndex-1; + //Trace.formatln( "dwthelper.utils getRelativeCodePointOffset {}: str={}, startIndex={}, searchRelCp={}", __LINE__, str, startIndex, searchRelCp ); + //tango.text.convert.Utf.onUnicodeError( "invalid utf8 input", i ); + } + } while(( str[i] & 0xDC00 ) is 0xDC00 ); + searchRelCp++; + } + } + return i; } dchar getRelativeCodePoint( String str, int startIndex, int searchRelCp, out int relIndex ){ relIndex = getRelativeCodePointOffset( str, startIndex, searchRelCp );