From e7d09237786428bb31b2c005dcded5b2f1b0dbf1 Mon Sep 17 00:00:00 2001 From: Weng Xuetian Date: Sat, 13 Apr 2024 23:38:15 -0700 Subject: [PATCH] Try to use set comment wherever possible. --- im/pinyin/pinyin.cpp | 16 ++++++---------- im/table/state.cpp | 19 ++++++++----------- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/im/pinyin/pinyin.cpp b/im/pinyin/pinyin.cpp index dc69b7fe..54351c5d 100644 --- a/im/pinyin/pinyin.cpp +++ b/im/pinyin/pinyin.cpp @@ -177,10 +177,9 @@ class StrokeCandidateWord : public CandidateWord, const std::string &py, int order) : PinyinAbstractExtraCandidateWordInterface(*this, order), engine_(engine), hz_(std::move(hz)) { - if (py.empty()) { - setText(Text(hz_)); - } else { - setText(Text(fmt::format(_("{0} ({1})"), hz_, py))); + setText(Text(hz_)); + if (!py.empty()) { + setComment(Text(py)); } } @@ -218,14 +217,11 @@ class PinyinPunctuationCandidateWord : public CandidateWord { public: PinyinPunctuationCandidateWord(const PinyinEngine *engine, std::string word, bool isHalf) - : CandidateWord(), engine_(engine), word_(std::move(word)) { - Text text; + : engine_(engine), word_(std::move(word)) { + setText(Text(word_)); if (isHalf) { - text.append(fmt::format(_("{0} (Half)"), word_)); - } else { - text.append(word_); + setComment(Text(_("(Half)"))); } - setText(std::move(text)); } void select(InputContext *inputContext) const override { diff --git a/im/table/state.cpp b/im/table/state.cpp index b955dfc5..62598e91 100644 --- a/im/table/state.cpp +++ b/im/table/state.cpp @@ -81,19 +81,19 @@ class TablePinyinCandidateWord : public CandidateWord { const libime::TableBasedDictionary &dict, bool customHint) : engine_(engine), word_(std::move(word)) { - Text text; - text.append(word_); + setText(Text(word_)); if (utf8::lengthValidated(word_) == 1) { if (auto code = dict.reverseLookup(word_); !code.empty()) { - text.append(" ~ "); + Text comment; + comment.append("~ "); if (customHint) { - text.append(dict.hint(code)); + comment.append(dict.hint(code)); } else { - text.append(std::move(code)); + comment.append(std::move(code)); } + setComment(std::move(comment)); } } - setText(std::move(text)); } void select(InputContext *inputContext) const override { @@ -112,13 +112,10 @@ class TablePunctuationCandidateWord : public CandidateWord { TablePunctuationCandidateWord(TableState *state, std::string word, bool isHalf) : state_(state), word_(std::move(word)) { - Text text; + setText(Text(word_)); if (isHalf) { - text.append(fmt::format(_("{0} (Half)"), word_)); - } else { - text.append(word_); + setComment(Text(_("(Half)"))); } - setText(std::move(text)); } void select(InputContext *inputContext) const override {