Skip to content

Commit

Permalink
Minor fix
Browse files Browse the repository at this point in the history
  • Loading branch information
wengxt committed Dec 22, 2024
1 parent 15b3d50 commit 082f47a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 26 deletions.
43 changes: 21 additions & 22 deletions src/libime/pinyin/shuangpinprofile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@
#include "pinyindata.h"
#include "pinyinencoder.h"
#include "shuangpindata.h"
#include <algorithm>
#include <boost/algorithm/string.hpp>
#include <boost/algorithm/string/predicate.hpp>
#include <boost/algorithm/string/trim.hpp>
#include <boost/range/iterator_range.hpp>
#include <cassert>
#include <cstddef>
#include <fcitx-utils/charutils.h>
#include <fcitx-utils/macros.h>
#include <istream>
#include <map>
#include <memory>
#include <set>
#include <stdexcept>
#include <string>
#include <string_view>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

namespace libime {

Expand Down Expand Up @@ -302,11 +317,8 @@ class ShuangpinProfilePrivate {
newEntries;

if (correctionProfile != nullptr) {
auto correctionMap = correctionProfile->correctionMap();
for (const auto &sp : spTable_) {
const auto &input = sp.first;
auto &pys = sp.second;

const auto &correctionMap = correctionProfile->correctionMap();
for (const auto &[input, pys] : spTable_) {
for (size_t i = 0; i < input.size(); i++) {
auto chr = input[i];
auto swap = correctionMap.find(chr);
Expand All @@ -327,9 +339,9 @@ class ShuangpinProfilePrivate {
}
}

for (const auto &newEntry : newEntries) {
auto &pys = spTable_[std::get<0>(newEntry)];
pys.emplace(std::get<1>(newEntry), std::get<2>(newEntry));
for (const auto &[input, syllable, flags] : newEntries) {
auto &pys = spTable_[input];
pys.emplace(syllable, flags);
}

for (const auto &sp : spTable_) {
Expand All @@ -345,19 +357,6 @@ ShuangpinProfile::ShuangpinProfile(ShuangpinBuiltinProfile profile)
ShuangpinProfile::ShuangpinProfile(std::istream &in)
: ShuangpinProfile::ShuangpinProfile(in, nullptr) {}

ShuangpinProfile::ShuangpinProfile(
const ShuangpinProfile &rhs,
const PinyinCorrectionProfile *correctionProfile)
: d_ptr(std::make_unique<ShuangpinProfilePrivate>()) {
FCITX_D();
d->zeroS_ = rhs.d_ptr->zeroS_;
d->finalMap_ = rhs.d_ptr->finalMap_;
d->initialMap_ = rhs.d_ptr->initialMap_;
d->initialFinalMap_ = rhs.d_ptr->initialFinalMap_;
d->finalSet_ = rhs.d_ptr->finalSet_;
d->buildShuangpinTable(correctionProfile);
}

ShuangpinProfile::ShuangpinProfile(
ShuangpinBuiltinProfile profile,
const PinyinCorrectionProfile *correctionProfile)
Expand Down Expand Up @@ -491,7 +490,7 @@ ShuangpinProfile::ShuangpinProfile(

FCITX_DEFINE_DPTR_COPY_AND_DEFAULT_DTOR_AND_MOVE(ShuangpinProfile)

// moved to ShuangpinProfilePrivate::buildShuangpinTable
// Deprecated, keep to only keep ABI stable.
void ShuangpinProfile::buildShuangpinTable() {}

const ShuangpinProfile::TableType &ShuangpinProfile::table() const {
Expand Down
3 changes: 0 additions & 3 deletions src/libime/pinyin/shuangpinprofile.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ class LIBIMEPINYIN_EXPORT ShuangpinProfile {
explicit ShuangpinProfile(std::istream &in,
const PinyinCorrectionProfile *correctionProfile);

explicit ShuangpinProfile(const ShuangpinProfile &rhs,
const PinyinCorrectionProfile *correctionProfile);

FCITX_DECLARE_VIRTUAL_DTOR_COPY_AND_MOVE(ShuangpinProfile)

const TableType &table() const;
Expand Down
2 changes: 1 addition & 1 deletion test/testpinyinime_unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ int main() {
ime.setCorrectionProfile(std::make_shared<PinyinCorrectionProfile>(
BuiltinPinyinCorrectionProfile::Qwerty));
ime.setShuangpinProfile(std::make_shared<libime::ShuangpinProfile>(
*ime.shuangpinProfile(), ime.correctionProfile().get()));
ShuangpinBuiltinProfile::Xiaohe, ime.correctionProfile().get()));
ime.setFuzzyFlags(flags | PinyinFuzzyFlag::Correction);

c.type("bkqiln");
Expand Down

0 comments on commit 082f47a

Please sign in to comment.