From bf46716fe363884e4b3dee85c248b50f08efcd6a Mon Sep 17 00:00:00 2001 From: ksqsf Date: Mon, 17 Jun 2024 21:59:12 +0200 Subject: [PATCH] fix SingleCharOnlyTranslation constructor --- src/rime/gear/single_char_filter.cc | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/src/rime/gear/single_char_filter.cc b/src/rime/gear/single_char_filter.cc index 0c9b4a8d55..6aa00d6698 100644 --- a/src/rime/gear/single_char_filter.cc +++ b/src/rime/gear/single_char_filter.cc @@ -66,21 +66,19 @@ class SingleCharOnlyTranslation : public Translation { an Peek() override; private: + bool SkipToNextChar(); + an translation_; an current_; }; SingleCharOnlyTranslation::SingleCharOnlyTranslation( an translation) - : translation_(translation) {} - -an 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); @@ -88,11 +86,19 @@ bool SingleCharOnlyTranslation::Next() { return false; } current_ = translation_->Peek(); - if (unistrlen(current_->text()) == 1) { + if (unistrlen(current_->text()) == 1) return true; - } } - assert(false); // unreachable +} + +an SingleCharOnlyTranslation::Peek() { + return current_; +} + +bool SingleCharOnlyTranslation::Next() { + if (exhausted()) + return false; + return SkipToNextChar(); } SingleCharFilter::SingleCharFilter(const Ticket& ticket) : Filter(ticket) {