Skip to content

Commit

Permalink
fix: don't compress the token during collecting dict entries (#762) (#…
Browse files Browse the repository at this point in the history
…768)

follow the default split behavior of boost::split
  • Loading branch information
WhiredPlanck authored Nov 26, 2023
1 parent bafe97f commit 767ebad
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
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

0 comments on commit 767ebad

Please sign in to comment.