diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/CellBuffer.cxx | 9 | ||||
| -rw-r--r-- | src/UniConversion.h | 7 |
2 files changed, 10 insertions, 6 deletions
diff --git a/src/CellBuffer.cxx b/src/CellBuffer.cxx index 51264966d..cbc19f539 100644 --- a/src/CellBuffer.cxx +++ b/src/CellBuffer.cxx @@ -734,8 +734,7 @@ bool CellBuffer::ContainsLineEnd(const char *s, Sci::Position length) const noex if ((ch == '\r') || (ch == '\n')) { return true; } else if (utf8LineEnds) { - const unsigned char back3[3] = { chBeforePrev, chPrev, ch }; - if (UTF8IsSeparator(back3) || UTF8IsNEL(back3 + 1)) { + if (UTF8IsMultibyteLineEnd(chBeforePrev, chPrev, ch)) { return true; } } @@ -907,8 +906,7 @@ void CellBuffer::ResetLineEnds() { lineInsert++; } } else if (utf8LineEnds) { - const unsigned char back3[3] = {chBeforePrev, chPrev, ch}; - if (UTF8IsSeparator(back3) || UTF8IsNEL(back3+1)) { + if (UTF8IsMultibyteLineEnd(chBeforePrev, chPrev, ch)) { InsertLine(lineInsert, (position + i) + 1, atLineStart); lineInsert++; } @@ -1081,8 +1079,7 @@ void CellBuffer::BasicInsertString(Sci::Position position, const char *s, Sci::P InsertLine(lineInsert, (position + ptr - s), atLineStart); lineInsert++; } else if (utf8LineEnds && !UTF8IsAscii(ch)) { - const unsigned char back3[3] = { chBeforePrev, chPrev, ch }; - if (UTF8IsSeparator(back3) || UTF8IsNEL(back3 + 1)) { + if (UTF8IsMultibyteLineEnd(chBeforePrev, chPrev, ch)) { InsertLine(lineInsert, (position + ptr - s), atLineStart); lineInsert++; } diff --git a/src/UniConversion.h b/src/UniConversion.h index 979075f5a..0c7adff10 100644 --- a/src/UniConversion.h +++ b/src/UniConversion.h @@ -71,6 +71,13 @@ inline bool UTF8IsNEL(const unsigned char *us) noexcept { return (us[0] == 0xc2) && (us[1] == 0x85); } +// Is the sequence of 3 char a UTF-8 line end? Only the last two char are tested for a NEL. +constexpr bool UTF8IsMultibyteLineEnd(unsigned char ch0, unsigned char ch1, unsigned char ch2) noexcept { + return + ((ch0 == 0xe2) && (ch1 == 0x80) && ((ch2 == 0xa8) || (ch2 == 0xa9))) || + ((ch1 == 0xc2) && (ch2 == 0x85)); +} + enum { SURROGATE_LEAD_FIRST = 0xD800 }; enum { SURROGATE_LEAD_LAST = 0xDBFF }; enum { SURROGATE_TRAIL_FIRST = 0xDC00 }; |
