aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2021-07-02 10:13:21 +1000
committerZufu Liu <unknown>2021-07-02 10:13:21 +1000
commit7b646db9fbfb71c41c477b01d99e1e1c6c85cef8 (patch)
treed0886cd0c743eed7d1ef4fca864c1f1bf474e0d3 /src
parent12dabace25a229d74db880473ecb7a5081bc65b9 (diff)
downloadscintilla-mirror-7b646db9fbfb71c41c477b01d99e1e1c6c85cef8.tar.gz
Feature [feature-requests:#1408] Treat valid DBCS lead byte followed by invalid
trail byte as single byte.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx19
1 files changed, 13 insertions, 6 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index c3fcf10c3..876e95b4f 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -892,11 +892,13 @@ Document::CharacterExtracted Document::CharacterAfter(Sci::Position position) co
return CharacterExtracted(UnicodeFromUTF8(charBytes), utf8status & UTF8MaskWidth);
}
} else {
- if (IsDBCSLeadByteNoExcept(leadByte) && ((position + 1) < LengthNoExcept())) {
- return CharacterExtracted::DBCS(leadByte, cb.UCharAt(position + 1));
- } else {
- return CharacterExtracted(leadByte, 1);
+ if (IsDBCSLeadByteNoExcept(leadByte)) {
+ const unsigned char trailByte = cb.UCharAt(position + 1);
+ if (!IsDBCSTrailByteInvalid(trailByte)) {
+ return CharacterExtracted::DBCS(leadByte, trailByte);
+ }
}
+ return CharacterExtracted(leadByte, 1);
}
}
@@ -1007,8 +1009,13 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio
}
} else {
if (IsDBCSLeadByteNoExcept(leadByte)) {
- bytesInCharacter = 2;
- character = (leadByte << 8) | cb.UCharAt(position+1);
+ const unsigned char trailByte = cb.UCharAt(position + 1);
+ if (!IsDBCSTrailByteInvalid(trailByte)) {
+ bytesInCharacter = 2;
+ character = (leadByte << 8) | trailByte;
+ } else {
+ character = leadByte;
+ }
} else {
character = leadByte;
}