diff --git a/src/rime/algo/encoder.cc b/src/rime/algo/encoder.cc index 8f117a96d5..64290424a8 100644 --- a/src/rime/algo/encoder.cc +++ b/src/rime/algo/encoder.cc @@ -20,7 +20,8 @@ string RawCode::ToString() const { } void RawCode::FromString(const string& code_str) { - *dynamic_cast*>(this) = strings::split(code_str, " "); + *dynamic_cast*>(this) = + strings::split(code_str, " ", strings::SplitBehavior::SkipToken); } TableEncoder::TableEncoder(PhraseCollector* collector) diff --git a/src/rime/algo/strings.cc b/src/rime/algo/strings.cc index a0ab82626a..acbb040ae9 100644 --- a/src/rime/algo/strings.cc +++ b/src/rime/algo/strings.cc @@ -8,7 +8,7 @@ vector split(const string& str, SplitBehavior behavior) { vector strings; size_t lastPos, pos; - if (behavior == SplitBehavior::SkipEmpty) { + if (behavior == SplitBehavior::SkipToken) { lastPos = str.find_first_not_of(delim, 0); } else { lastPos = 0; @@ -17,7 +17,7 @@ vector split(const string& str, while (std::string::npos != pos || std::string::npos != lastPos) { strings.emplace_back(str.substr(lastPos, pos - lastPos)); - if (behavior == SplitBehavior::SkipEmpty) { + if (behavior == SplitBehavior::SkipToken) { lastPos = str.find_first_not_of(delim, pos); } else { if (pos == std::string::npos) { @@ -31,7 +31,7 @@ vector split(const string& str, }; vector split(const string& str, const string& delim) { - return split(str, delim, SplitBehavior::SkipEmpty); + return split(str, delim, SplitBehavior::KeepToken); }; } // namespace strings diff --git a/src/rime/algo/strings.h b/src/rime/algo/strings.h index 2bd570f1c6..222476d2fa 100644 --- a/src/rime/algo/strings.h +++ b/src/rime/algo/strings.h @@ -7,7 +7,7 @@ namespace rime { namespace strings { -enum class SplitBehavior { KeepEmpty, SkipEmpty }; +enum class SplitBehavior { KeepToken, SkipToken }; vector split(const string& str, const string& delim, diff --git a/src/rime/gear/ascii_composer.cc b/src/rime/gear/ascii_composer.cc index 18889f3ac4..906e447eea 100644 --- a/src/rime/gear/ascii_composer.cc +++ b/src/rime/gear/ascii_composer.cc @@ -224,7 +224,9 @@ void AsciiComposer::SwitchAsciiMode(bool ascii_mode, [this](Context* ctx) { OnContextUpdate(ctx); }); } } else if (style == kAsciiModeSwitchCommitText) { - ctx->ConfirmCurrentSelection(); + while (ctx->composition().back().end < ctx->input().length()) + ctx->ConfirmCurrentSelection(); + ctx->Commit(); } else if (style == kAsciiModeSwitchCommitCode) { ctx->ClearNonConfirmedComposition(); ctx->Commit(); diff --git a/src/rime/gear/shape.cc b/src/rime/gear/shape.cc index b6a16774e3..09748afa00 100644 --- a/src/rime/gear/shape.cc +++ b/src/rime/gear/shape.cc @@ -18,7 +18,7 @@ void ShapeFormatter::Format(string* text) { return; } if (std::all_of(text->cbegin(), text->cend(), - [](auto ch) { return (ch >= 0x20 && ch <= 0x7e); })) { + [](auto ch) { return (ch < 0x20 || ch > 0x7e); })) { return; } std::ostringstream oss;