Skip to content

Commit

Permalink
fix SingleCharOnlyTranslation constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ksqsf committed Jun 17, 2024
1 parent 60e0610 commit bf46716
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/rime/gear/single_char_filter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -66,33 +66,39 @@ class SingleCharOnlyTranslation : public Translation {
an<Candidate> Peek() override;

private:
bool SkipToNextChar();

an<Translation> translation_;
an<Candidate> current_;
};

SingleCharOnlyTranslation::SingleCharOnlyTranslation(
an<Translation> translation)
: translation_(translation) {}

an<Candidate> SingleCharOnlyTranslation::Peek() {
return current_;
: translation_(translation) {
SkipToNextChar();
}

bool SingleCharOnlyTranslation::Next() {
if (exhausted())
return false;
bool SingleCharOnlyTranslation::SkipToNextChar() {
while (true) {
if (translation_->exhausted() || !translation_->Next()) {
set_exhausted(true);
current_.reset();
return false;
}
current_ = translation_->Peek();
if (unistrlen(current_->text()) == 1) {
if (unistrlen(current_->text()) == 1)
return true;
}
}
assert(false); // unreachable
}

an<Candidate> SingleCharOnlyTranslation::Peek() {
return current_;
}

bool SingleCharOnlyTranslation::Next() {
if (exhausted())
return false;
return SkipToNextChar();
}

SingleCharFilter::SingleCharFilter(const Ticket& ticket) : Filter(ticket) {
Expand Down

0 comments on commit bf46716

Please sign in to comment.