Mercurial > projects > dwt-addons
diff dwtx/jface/internal/text/html/HTML2TextReader.d @ 162:1a5b8f8129df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 08 Sep 2008 00:51:37 +0200 |
parents | 25f1f92fa3df |
children | c6d7b1ea700b |
line wrap: on
line diff
--- a/dwtx/jface/internal/text/html/HTML2TextReader.d Wed Aug 27 14:49:30 2008 +0200 +++ b/dwtx/jface/internal/text/html/HTML2TextReader.d Mon Sep 08 00:51:37 2008 +0200 @@ -24,6 +24,7 @@ import dwt.dwthelper.utils; import dwtx.dwtxhelper.PushbackReader; import dwtx.dwtxhelper.Collection; +static import tango.text.convert.Utf; import dwt.DWT; import dwt.custom.StyleRange; @@ -190,7 +191,7 @@ if ("li".equals(html)) //$NON-NLS-1$ // FIXME: this hard-coded prefix does not work for RTL languages, see https://bugs.eclipse.org/bugs/show_bug.cgi?id=91682 - return LINE_DELIM + HTMLMessages.getString("HTML2TextReader.listItemPrefix"); //$NON-NLS-1$ + return LINE_DELIM ~ HTMLMessages.getString("HTML2TextReader.listItemPrefix"); //$NON-NLS-1$ if ("/b".equals(html)) { //$NON-NLS-1$ stopBold(); @@ -242,22 +243,22 @@ int ch; do { - ch= nextChar(); + ch= nextDChar(); while (ch !is -1 && ch !is '>') { - buf.append(Character.toLowerCase(cast(wchar) ch)); - ch= nextChar(); + buf.append(dcharToString(Character.toLowerCase(cast(dchar) ch))); + ch= nextDChar(); if (ch is '"'){ - buf.append(Character.toLowerCase(cast(wchar) ch)); - ch= nextChar(); + buf.append(dcharToString(Character.toLowerCase(cast(dchar) ch))); + ch= nextDChar(); while (ch !is -1 && ch !is '"'){ - buf.append(Character.toLowerCase(cast(wchar) ch)); - ch= nextChar(); + buf.append(dcharToString(Character.toLowerCase(cast(dchar) ch))); + ch= nextDChar(); } } if (ch is '<' && !isInComment(buf)) { - unread(ch); - return '<' + buf.toString(); + unreadDChar(ch); + return '<' ~ buf.toString(); } } @@ -268,19 +269,19 @@ break; } // unfinished comment - buf.append(cast(wchar) ch); + buf.append(dcharToString(cast(dchar) ch)); } while (true); return html2Text(buf.toString()); } private static bool isInComment(StringBuffer buf) { - return buf.length() >= 3 && "!--".equals(buf.substring(0, 3)); //$NON-NLS-1$ + return buf.length() >= 3 && "!--".equals(buf.slice().substring(0, 3)); //$NON-NLS-1$ } private static bool isCommentEnd(StringBuffer buf) { int tagLen= buf.length(); - return tagLen >= 5 && "--".equals(buf.substring(tagLen - 2)); //$NON-NLS-1$ + return tagLen >= 5 && "--".equals(buf.slice().substring(tagLen - 2)); //$NON-NLS-1$ } private String processPreformattedText(int c) { @@ -290,8 +291,13 @@ } - private void unread(int ch) { - (cast(PushbackReader) getReader()).unread(ch); + private void unreadDChar(dchar ch) { + char[4] buf; + dchar[1] ibuf; + ibuf[0] = ch; + foreach( char c; tango.text.convert.Utf.toString( ibuf[], buf[] )){ + (cast(PushbackReader) getReader()).unread(c); + } } protected String entity2Text(String symbol) { @@ -303,16 +309,16 @@ } else { ch= Integer.parseInt(symbol.substring(1), 10); } - return EMPTY_STRING + cast(wchar)ch; + return dcharToString( cast(dchar)ch); } catch (NumberFormatException e) { } } else { - String str= cast(String) fgEntityLookup.get(symbol); + String str= stringcast( fgEntityLookup.get(symbol)); if (str !is null) { return str; } } - return "&" + symbol; // not found //$NON-NLS-1$ + return "&" ~ symbol; // not found //$NON-NLS-1$ } /* @@ -320,18 +326,19 @@ */ private String processEntity() { StringBuffer buf= new StringBuffer(); - int ch= nextChar(); - while (Character.isLetterOrDigit(cast(wchar)ch) || ch is '#') { - buf.append(cast(wchar) ch); - ch= nextChar(); + int ch= nextDChar(); + while (Character.isLetterOrDigit(cast(dchar)ch) || ch is '#') { + buf.append(dcharToString(cast(dchar) ch)); + ch= nextDChar(); } if (ch is ';') return entity2Text(buf.toString()); - buf.insert(0, '&'); + buf.select(0, 0); + buf.prepend("&"); if (ch !is -1) - buf.append(cast(wchar) ch); + buf.append(dcharToString(cast(dchar) ch)); return buf.toString(); } }