From a2d23bd463e65f532301b682b64cd02b8a57716b Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Sat, 3 Jul 2021 13:21:38 +1000 Subject: Feature [feature-requests:#1408] Simplify code, remove IsDBCSTrailByteInvalid. Drop temporary test for IsDBCSTrailByteNoExcept. --- src/Document.cxx | 76 ++++++++++---------------------------------------------- src/Document.h | 1 - 2 files changed, 13 insertions(+), 64 deletions(-) (limited to 'src') diff --git a/src/Document.cxx b/src/Document.cxx index 739b6266a..0ec598bc2 100644 --- a/src/Document.cxx +++ b/src/Document.cxx @@ -985,27 +985,22 @@ Sci::Position Document::GetRelativePositionUTF16(Sci::Position positionStart, Sc } int SCI_METHOD Document::GetCharacterAndWidth(Sci_Position position, Sci_Position *pWidth) const { - int character; int bytesInCharacter = 1; const unsigned char leadByte = cb.UCharAt(position); - if (dbcsCodePage) { + int character = leadByte; + if (dbcsCodePage && !UTF8IsAscii(leadByte)) { if (CpUtf8 == dbcsCodePage) { - if (UTF8IsAscii(leadByte)) { - // Single byte character or invalid - character = leadByte; + const int widthCharBytes = UTF8BytesOfLead[leadByte]; + unsigned char charBytes[UTF8MaxBytes] = {leadByte,0,0,0}; + for (int b=1; b= 0xFD); - case 936: - // GBK - return - (trail <= 0x3F) || - (trail == 0x7F) || - (trail == 0xFF); - case 949: - // Korean Wansung KS C-5601-1987 - return - (trail <= 0x40) || - ((trail >= 0x5B) && (trail <= 0x60)) || - ((trail >= 0x7B) && (trail <= 0x80)) || - (trail == 0xFF); - case 950: - // Big5 - return - (trail <= 0x3F) || - ((trail >= 0x7F) && (trail <= 0xA0)) || - (trail == 0xFF); - case 1361: - // Korean Johab KS C-5601-1992 - return - (trail <= 0x30) || - (trail == 0x7F) || - (trail == 0x80) || - (trail == 0xFF); - } - return false; -} - int Document::DBCSDrawBytes(std::string_view text) const noexcept { if (text.length() <= 1) { return static_cast(text.length()); } if (IsDBCSLeadByteNoExcept(text[0])) { - return IsDBCSTrailByteInvalid(text[1]) ? 1 : 2; + return IsDBCSTrailByteNoExcept(text[1]) ? 2 : 1; } else { return 1; } diff --git a/src/Document.h b/src/Document.h index 88392c1a2..c40ce2a44 100644 --- a/src/Document.h +++ b/src/Document.h @@ -331,7 +331,6 @@ public: 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; int SafeSegment(const char *text, int length, int lengthSegment) const noexcept; EncodingFamily CodePageFamily() const noexcept; -- cgit v1.2.3