aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorZufu Liu <unknown>2021-07-03 12:59:39 +1000
committerZufu Liu <unknown>2021-07-03 12:59:39 +1000
commit9cda372c64c8920d2e910825161a8ed882b417b3 (patch)
treeef5ed7a0110c22327c6bb09d3f6b481ddfa83284 /src
parent4a34a1f59a443403844c437d6d6a61c7a8019822 (diff)
downloadscintilla-mirror-9cda372c64c8920d2e910825161a8ed882b417b3.tar.gz
Feature [feature-requests:#1408] Use positive IsDBCSTrailByteNoExcept function
instead of negated IsDBCSTrailByteInvalid.
Diffstat (limited to 'src')
-rw-r--r--src/Document.cxx35
-rw-r--r--src/Document.h1
2 files changed, 34 insertions, 2 deletions
diff --git a/src/Document.cxx b/src/Document.cxx
index 876e95b4f..739b6266a 100644
--- a/src/Document.cxx
+++ b/src/Document.cxx
@@ -894,7 +894,7 @@ Document::CharacterExtracted Document::CharacterAfter(Sci::Position position) co
} else {
if (IsDBCSLeadByteNoExcept(leadByte)) {
const unsigned char trailByte = cb.UCharAt(position + 1);
- if (!IsDBCSTrailByteInvalid(trailByte)) {
+ if (IsDBCSTrailByteNoExcept(trailByte)) {
return CharacterExtracted::DBCS(leadByte, trailByte);
}
}
@@ -1010,7 +1010,7 @@ int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Positio
} else {
if (IsDBCSLeadByteNoExcept(leadByte)) {
const unsigned char trailByte = cb.UCharAt(position + 1);
- if (!IsDBCSTrailByteInvalid(trailByte)) {
+ if (IsDBCSTrailByteNoExcept(trailByte)) {
bytesInCharacter = 2;
character = (leadByte << 8) | trailByte;
} else {
@@ -1067,6 +1067,37 @@ bool Document::IsDBCSLeadByteNoExcept(char ch) const noexcept {
return false;
}
+bool Document::IsDBCSTrailByteNoExcept(char ch) const noexcept {
+ const unsigned char trail = ch;
+ switch (dbcsCodePage) {
+ case 932:
+ // Shift_jis
+ return (trail != 0x7F) &&
+ ((trail >= 0x40) && (trail <= 0xFC));
+ case 936:
+ // GBK
+ return (trail != 0x7F) &&
+ ((trail >= 0x40) && (trail <= 0xFE));
+ case 949:
+ // Korean Wansung KS C-5601-1987
+ return
+ ((trail >= 0x41) && (trail <= 0x5A)) ||
+ ((trail >= 0x61) && (trail <= 0x7A)) ||
+ ((trail >= 0x81) && (trail <= 0xFE));
+ case 950:
+ // Big5
+ return
+ ((trail >= 0x40) && (trail <= 0x7E)) ||
+ ((trail >= 0xA1) && (trail <= 0xFE));
+ case 1361:
+ // Korean Johab KS C-5601-1992
+ return
+ ((trail >= 0x31) && (trail <= 0x7E)) ||
+ ((trail >= 0x81) && (trail <= 0xFE));
+ }
+ return false;
+}
+
bool Document::IsDBCSLeadByteInvalid(char ch) const noexcept {
const unsigned char lead = ch;
switch (dbcsCodePage) {
diff --git a/src/Document.h b/src/Document.h
index 09d5841ed..88392c1a2 100644
--- a/src/Document.h
+++ b/src/Document.h
@@ -329,6 +329,7 @@ public:
int SCI_METHOD CodePage() const override;
bool SCI_METHOD IsDBCSLeadByte(char ch) const override;
bool IsDBCSLeadByteNoExcept(char ch) const noexcept;
+ bool IsDBCSTrailByteNoExcept(char ch) const noexcept;
bool IsDBCSLeadByteInvalid(char ch) const noexcept;
bool IsDBCSTrailByteInvalid(char ch) const noexcept;
int DBCSDrawBytes(std::string_view text) const noexcept;