diff options
author | Dani Megert | 2010-04-12 13:15:16 +0000 |
---|---|---|
committer | Dani Megert | 2010-04-12 13:15:16 +0000 |
commit | 4a85796e1c0db6c5956ca003b0739a7083954c53 (patch) | |
tree | 6d3fe18da11ddea923ff1c9a779bb265d1c708d8 | |
parent | 04c40e4970ca2088f769f8249f7e915483646872 (diff) | |
download | eclipse.platform.text-4a85796e1c0db6c5956ca003b0739a7083954c53.tar.gz eclipse.platform.text-4a85796e1c0db6c5956ca003b0739a7083954c53.tar.xz eclipse.platform.text-4a85796e1c0db6c5956ca003b0739a7083954c53.zip |
Improved previous fix to also handle combined characters.
-rw-r--r-- | org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java | 45 |
1 files changed, 8 insertions, 37 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java index 5a0b95b746a..b99e17485fa 100644 --- a/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java +++ b/org.eclipse.ui.editors/src/org/eclipse/ui/texteditor/AbstractDecoratedTextEditor.java @@ -18,6 +18,7 @@ import java.nio.charset.UnsupportedCharsetException; import java.util.Iterator; import java.util.List; +import com.ibm.icu.text.BreakIterator; import com.ibm.icu.text.MessageFormat; import org.eclipse.swt.SWT; @@ -207,31 +208,6 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor { /** - * The surrogate bits. - * @since 3.6 - */ - private static final int SURROGATE_BITS= 0xD800; - /** - * The surrogate bitmask. - * @since 3.6 - */ - private static final int SURROGATE_BITMASK= 0xFFFFF800; - /** - * Tells whether the given character is a surrogate. - * <p> - * <strong>Note:</strong> We cannot use {@link com.ibm.icu.text.UTF16} since this is not in the - * <code>com.ibm.icu.base</code> bundle.</p> - * - * @param ch the character - * @return <code>true</code> if the character is a surrogate - * @since 3.6 - */ - private static boolean isSurrogate(char ch) { - return (ch & SURROGATE_BITMASK) == SURROGATE_BITS; - } - - - /** * Adapter class for <code>IGotoMarker</code>. */ private class GotoMarkerAdapter implements IGotoMarker { @@ -1658,26 +1634,21 @@ public abstract class AbstractDecoratedTextEditor extends StatusTextEditor { IDocument document= getDocumentProvider().getDocument(getEditorInput()); int documentLength= document.getLength(); int offset= 0; + BreakIterator charBreakIterator= BreakIterator.getCharacterInstance(); + charBreakIterator.setText(document.get()); while (offset < documentLength) { try { - char ch= document.getChar(offset); - if (isSurrogate(ch)) { - offset++; - char trail= document.getChar(offset); - char[] supplement= { ch, trail }; - if (!encoder.canEncode(new String(supplement))) { - selectAndReveal(offset - 1, 2); - return; - } - } else if (!encoder.canEncode(ch)) { - selectAndReveal(offset, 1); + int next= charBreakIterator.next(); + String ch= document.get(offset, next - offset); + if (!encoder.canEncode(ch)) { + selectAndReveal(offset, next - offset); return; } + offset= next; } catch (BadLocationException ex) { EditorsPlugin.log(ex); // Skip this character. Showing yet another dialog here is overkill } - offset++; } } } |