diff options
author | Neil <nyamatongwe@gmail.com> | 2025-03-08 11:44:57 +1100 |
---|---|---|
committer | Neil <nyamatongwe@gmail.com> | 2025-03-08 11:44:57 +1100 |
commit | 386fb7a89ffbff9497d8e9ce7d7f44c038c49729 (patch) | |
tree | 08229fc3cb3f4d60bd3b45afb5f90025fcbc45fc /src/UniConversion.h | |
parent | 102fa1d501808187235f93670591d5b9d1253778 (diff) | |
download | scintilla-mirror-386fb7a89ffbff9497d8e9ce7d7f44c038c49729.tar.gz |
Define constants for UTF-8 and UTF-16 implementation for clarity.
Add tests to check that inverted conversions yield the original value.
Diffstat (limited to 'src/UniConversion.h')
-rw-r--r-- | src/UniConversion.h | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/src/UniConversion.h b/src/UniConversion.h index 5990cca8c..ce5de4bc7 100644 --- a/src/UniConversion.h +++ b/src/UniConversion.h @@ -99,8 +99,12 @@ enum { SURROGATE_TRAIL_FIRST = 0xDC00 }; enum { SURROGATE_TRAIL_LAST = 0xDFFF }; enum { SUPPLEMENTAL_PLANE_FIRST = 0x10000 }; +constexpr bool IsSurrogate(wchar_t uch) noexcept { + return (uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_TRAIL_LAST); +} + constexpr unsigned int UTF16CharLength(wchar_t uch) noexcept { - return ((uch >= SURROGATE_LEAD_FIRST) && (uch <= SURROGATE_LEAD_LAST)) ? 2 : 1; + return IsSurrogate(uch) ? 2 : 1; } constexpr unsigned int UTF16LengthFromUTF8ByteCount(unsigned int byteCount) noexcept { |