Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix: correct the split behavior during collecting dict entries #768

Merged
merged 1 commit into from
Nov 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/rime/algo/encoder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ string RawCode::ToString() const {
}

void RawCode::FromString(const string& code_str) {
*dynamic_cast<vector<string>*>(this) = strings::split(code_str, " ");
*dynamic_cast<vector<string>*>(this) =
strings::split(code_str, " ", strings::SplitBehavior::SkipToken);
}

TableEncoder::TableEncoder(PhraseCollector* collector)
Expand Down
6 changes: 3 additions & 3 deletions src/rime/algo/strings.cc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ vector<string> split(const string& str,
SplitBehavior behavior) {
vector<string> strings;
size_t lastPos, pos;
if (behavior == SplitBehavior::SkipEmpty) {
if (behavior == SplitBehavior::SkipToken) {
lastPos = str.find_first_not_of(delim, 0);
} else {
lastPos = 0;
Expand All @@ -17,7 +17,7 @@ vector<string> 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) {
Expand All @@ -31,7 +31,7 @@ vector<string> split(const string& str,
};

vector<string> split(const string& str, const string& delim) {
return split(str, delim, SplitBehavior::SkipEmpty);
return split(str, delim, SplitBehavior::KeepToken);
};

} // namespace strings
Expand Down
2 changes: 1 addition & 1 deletion src/rime/algo/strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
namespace rime {
namespace strings {

enum class SplitBehavior { KeepEmpty, SkipEmpty };
enum class SplitBehavior { KeepToken, SkipToken };

vector<string> split(const string& str,
const string& delim,
Expand Down