Mercurial > projects > dwt-addons
diff dwtx/jface/internal/text/html/SubstitutionTextReader.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 7926b636c282 |
children |
line wrap: on
line diff
--- a/dwtx/jface/internal/text/html/SubstitutionTextReader.d Wed Aug 27 14:49:30 2008 +0200 +++ b/dwtx/jface/internal/text/html/SubstitutionTextReader.d Mon Sep 08 00:51:37 2008 +0200 @@ -21,8 +21,8 @@ import dwtx.jface.internal.text.html.BrowserInformationControlInput; // packageimport import dwtx.jface.internal.text.html.HTMLMessages; // packageimport - import dwt.dwthelper.utils; +import tango.core.Exception; /** * Reads the text contents from a reader and computes for each character @@ -92,9 +92,9 @@ protected int nextChar() { fReadFromBuffer= (fBuffer.length() > 0); if (fReadFromBuffer) { - char ch= fBuffer.charAt(fIndex++); + char ch= fBuffer.slice().charAt(fIndex++); if (fIndex >= fBuffer.length()) { - fBuffer.setLength(0); + fBuffer.truncate(0); fIndex= 0; } return ch; @@ -104,10 +104,10 @@ if (ch is -1) { ch= fReader.read(); } - if (fSkipWhiteSpace && Character.isWhitespace(cast(wchar)ch)) { + if (fSkipWhiteSpace && Character.isWhitespace(cast(char)ch)) { do { ch= fReader.read(); - } while (Character.isWhitespace(cast(wchar)ch)); + } while (Character.isWhitespace(cast(char)ch)); if (ch !is -1) { fCharAfterWhiteSpace= ch; return ' '; @@ -118,6 +118,46 @@ return ch; } + /// DWT + protected int nextDChar() { + char[4] buf = void; + int ch1 = nextChar(); + if( ch1 is -1 ) return -1; + buf[0] = cast(char)ch1; + if(( ch1 & 0x80 ) is 0x00 ){ + return ch1; + } + else if(( ch1 & 0xE0 ) is 0xC0 ){ + int ch2 = nextChar(); + if( ch2 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[1] = cast(char)ch2; + } + else if(( ch1 & 0xF0 ) is 0xE0 ){ + int ch2 = nextChar(); + if( ch1 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[1] = cast(char)ch2; + int ch3 = nextChar(); + if( ch3 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[2] = cast(char)ch3; + } + else if(( ch1 & 0xF8 ) is 0xF0 ){ + int ch2 = nextChar(); + if( ch1 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[1] = cast(char)ch2; + int ch3 = nextChar(); + if( ch3 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[2] = cast(char)ch3; + int ch4 = nextChar(); + if( ch4 is -1 ) throw new UnicodeException(__FILE__,__LINE__); + buf[3] = cast(char)ch4; + } + else { + throw new UnicodeException(__FILE__,__LINE__); + } + uint ate; + return tango.text.convert.Utf.decode( buf, ate ); + } + /** * @see Reader#read() */ @@ -130,8 +170,10 @@ String s= computeSubstitution(c); if (s is null) break; - if (s.length() > 0) - fBuffer.insert(0, s); + if (s.length() > 0){ + fBuffer.select(0, 0); + fBuffer.replace(s); + } c= nextChar(); } @@ -161,7 +203,7 @@ fReader.reset(); fWasWhiteSpace= true; fCharAfterWhiteSpace= -1; - fBuffer.setLength(0); + fBuffer.truncate(0); fIndex= 0; }