From ff707f0fe276677a4d89633ae4964e8b94712ca3 Mon Sep 17 00:00:00 2001 From: Zufu Liu Date: Thu, 22 Mar 2018 15:02:38 +1100 Subject: Feature [feature-requests:#1211]. Use pre-computed table for UTF8BytesOfLead. Friendlier treatment of invalid UTF-8. Add tests for UniConversion handling invalid UTF-8. Simplify UTF8Classify tests. --- win32/PlatWin.cxx | 19 ++++++++----------- win32/scintilla.mak | 2 +- 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'win32') diff --git a/win32/PlatWin.cxx b/win32/PlatWin.cxx index 9e89e2f84..79970a969 100644 --- a/win32/PlatWin.cxx +++ b/win32/PlatWin.cxx @@ -951,12 +951,14 @@ void SurfaceGDI::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION * return; } // Map the widths given for UTF-16 characters back onto the UTF-8 input string + const unsigned char *us = reinterpret_cast(s); for (int ui = 0; ui < fit; ui++) { - const unsigned int lenChar = UTF8BytesOfLead[static_cast(s[i])]; - if (lenChar == 4) { // Non-BMP + const unsigned char uch = us[i]; + const unsigned int byteCount = UTF8BytesOfLead[uch]; + if (byteCount == 4) { // Non-BMP ui++; } - for (unsigned int bytePos=0; (bytePos(poses.buffer[ui]); } } @@ -1623,16 +1625,11 @@ void SurfaceD2D::MeasureWidths(Font &font_, const char *s, int len, XYPOSITION * int i=0; while (ui= (0x80 + 0x40 + 0x20 + 0x10)) { - lenChar = 4; + const unsigned int byteCount = UTF8BytesOfLead[uch]; + if (byteCount == 4) { // Non-BMP ui++; - } else if (uch >= (0x80 + 0x40 + 0x20)) { - lenChar = 3; - } else if (uch >= (0x80)) { - lenChar = 2; } - for (unsigned int bytePos=0; (bytePos