apro:rbs.
This commit is contained in:
parent
a1fb6ec779
commit
3d369e81c2
@ -166,19 +166,16 @@ ofString CCodec::rbs(const ofString& str)
|
||||
std::vector<char32_t> 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);
|
||||
}
|
||||
|
||||
|
@ -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()
|
||||
|
Loading…
x
Reference in New Issue
Block a user