diff --git a/src/of_util.cpp b/src/of_util.cpp index f68b5f2..19d26ec 100644 --- a/src/of_util.cpp +++ b/src/of_util.cpp @@ -166,19 +166,16 @@ ofString CCodec::rbs(const ofString& str) std::vector processed_chars; bool last_was_whitespace = false; - for (size_t i = 0; i < unicode_chars.size(); ++i) { - char32_t current = unicode_chars[i]; - + for (char32_t current : unicode_chars) { bool is_whitespace = (current == U' ' || current == U'\t' || current == U'\n' || current == U'\r'); + if (is_whitespace) { - bool near_non_ascii = - (i > 0 && unicode_chars[i - 1] > 0x7F) || (i + 1 < unicode_chars.size() && unicode_chars[i + 1] > 0x7F); - if (near_non_ascii || last_was_whitespace) { - continue; - } - current = U' '; + last_was_whitespace = true; + continue; + } + if (last_was_whitespace) { + last_was_whitespace = false; } - last_was_whitespace = is_whitespace; processed_chars.push_back(current); } diff --git a/test/main.cpp b/test/main.cpp index bed1164..6dd3efe 100644 --- a/test/main.cpp +++ b/test/main.cpp @@ -25,6 +25,10 @@ void testC() std::string source(u8"这是 一 个测试 用例。 "); std::string expect(u8"这是一个测试用例。"); assert(CCodec::rbs(source) == expect); + + std::string source1(u8"1. 氣 壓 不 足 2. I/O 輸出未 設 定3.氣壓缸異常"); + std::string expect1(u8"1.氣壓不足2.I/O輸出未設定3.氣壓缸異常"); + assert(CCodec::rbs(source1) == expect1); } int main()