aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/common/StringUtil.cpp4
-rw-r--r--test/common/StringUtilTest.cpp6
2 files changed, 8 insertions, 2 deletions
diff --git a/src/common/StringUtil.cpp b/src/common/StringUtil.cpp
index 0b6332ce..0ebfd85e 100644
--- a/src/common/StringUtil.cpp
+++ b/src/common/StringUtil.cpp
@@ -16,7 +16,7 @@ CodePoint Utf16Iterator::Previous() {
if (cu0 < 0xd800u || cu0 >= 0xe000u) { // 1-length code point
return static_cast<CodePoint>(cu0);
- } else if (cu0 < 0xdc00u || cu0 > 0xdfffu) { // 2-length code point
+ } else if (cu0 >= 0xdc00u || cu0 <= 0xdfffu) { // 2-length code point
if (position_ <= 0) {
throw TextEncodeException(
"Unexpected end when reading first code unit of surrogate pair "
@@ -25,7 +25,7 @@ CodePoint Utf16Iterator::Previous() {
const auto cu1 = static_cast<std::uint16_t>(string_[--position_]);
#ifdef CRU_DEBUG
- if (cu1 <= 0xdbffu) {
+ if (cu1 < 0xd800u || cu1 > 0xdbffu) {
throw TextEncodeException(
"Unexpected bad-range first code unit of surrogate pair during "
"backward.");
diff --git a/test/common/StringUtilTest.cpp b/test/common/StringUtilTest.cpp
index e454505b..21a9ea9c 100644
--- a/test/common/StringUtilTest.cpp
+++ b/test/common/StringUtilTest.cpp
@@ -26,6 +26,12 @@ TEST(WinString, Utf16Iterator) {
ASSERT_EQ(i.Next(), 0x1F923);
ASSERT_EQ(i.Next(), 0x0021);
ASSERT_EQ(i.Next(), k_invalid_code_point);
+ ASSERT_EQ(i.Previous(), 0x0021);
+ ASSERT_EQ(i.Previous(), 0x1F923);
+ ASSERT_EQ(i.Previous(), 0x4F60);
+ ASSERT_EQ(i.Previous(), 0x03C0);
+ ASSERT_EQ(i.Previous(), 0x0061);
+ ASSERT_EQ(i.Previous(), k_invalid_code_point);
}
// TEST(WinString, IndexUtf8ToUtf16) {