diff options
author | Zufu Liu <unknown> | 2019-04-10 11:15:46 +1000 |
---|---|---|
committer | Zufu Liu <unknown> | 2019-04-10 11:15:46 +1000 |
commit | 811d07c8d4a7634ec80409b165a8447bd5ef951a (patch) | |
tree | e59617e8500f00a990eb169b90b6c98aea9e3067 | |
parent | fd5c1e542eff7358447ddda6d43f6a90b3045742 (diff) | |
download | scintilla-mirror-811d07c8d4a7634ec80409b165a8447bd5ef951a.tar.gz |
Backport: Bug [#2093]. Fix exception when inserting DBCS text.
Backport of changeset 7415:a7d3bc738c23.
-rw-r--r-- | doc/ScintillaHistory.html | 4 | ||||
-rw-r--r-- | src/Editor.cxx | 21 |
2 files changed, 17 insertions, 8 deletions
diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 471fdf42d..3e3b5cacb 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -582,6 +582,10 @@ <a href="https://sourceforge.net/p/scintilla/bugs/2087/">Bug #2087</a>. </li> <li> + Fix exception when inserting DBCS text. + <a href="https://sourceforge.net/p/scintilla/bugs/2093/">Bug #2093</a>. + </li> + <li> Avoid potential long hangs with idle styling for huge documents on Cocoa and GTK. </li> <li> diff --git a/src/Editor.cxx b/src/Editor.cxx index d67f97df7..d47ece75b 100644 --- a/src/Editor.cxx +++ b/src/Editor.cxx @@ -1900,6 +1900,9 @@ void Editor::FilterSelections() { // AddCharUTF inserts an array of bytes which may or may not be in UTF-8. void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) { + if (len == 0) { + return; + } FilterSelections(); { UndoGroup ug(pdoc, (sel.Count() > 1) || !sel.Empty() || inOverstrike); @@ -1970,12 +1973,14 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) { SetLastXChosen(); } - if (treatAsDBCS) { - NotifyChar((static_cast<unsigned char>(s[0]) << 8) | - static_cast<unsigned char>(s[1])); - } else if (len > 0) { - int byte = static_cast<unsigned char>(s[0]); - if ((byte < 0xC0) || (1 == len)) { + int ch = static_cast<unsigned char>(s[0]); + if (treatAsDBCS || pdoc->dbcsCodePage != SC_CP_UTF8) { + if (len > 1) { + // DBCS code page or DBCS font character set. + ch |= (ch << 8) | static_cast<unsigned char>(s[1]); + } + } else { + if ((ch < 0xC0) || (1 == len)) { // Handles UTF-8 characters between 0x01 and 0x7F and single byte // characters when not in UTF-8 mode. // Also treats \0 and naked trail bytes 0x80 to 0xBF as valid @@ -1983,10 +1988,10 @@ void Editor::AddCharUTF(const char *s, unsigned int len, bool treatAsDBCS) { } else { unsigned int utf32[1] = { 0 }; UTF32FromUTF8(s, len, utf32, ELEMENTS(utf32)); - byte = utf32[0]; + ch = utf32[0]; } - NotifyChar(byte); } + NotifyChar(ch); if (recordingMacro) { NotifyMacroRecord(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(s)); |