aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2019-04-10 11:15:46 +1000
committerZufu Liu <unknown>2019-04-10 11:15:46 +1000
commit811d07c8d4a7634ec80409b165a8447bd5ef951a (patch)
treee59617e8500f00a990eb169b90b6c98aea9e3067 /src
parentfd5c1e542eff7358447ddda6d43f6a90b3045742 (diff)
downloadscintilla-mirror-811d07c8d4a7634ec80409b165a8447bd5ef951a.tar.gz
Backport: Bug [#2093]. Fix exception when inserting DBCS text.
Backport of changeset 7415:a7d3bc738c23.
Diffstat (limited to 'src')
-rw-r--r--src/Editor.cxx21
1 files changed, 13 insertions, 8 deletions
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));