Skip to content

Commit

Permalink
Address feedback from @lukhnos
Browse files Browse the repository at this point in the history
  • Loading branch information
xatier committed Aug 19, 2023
1 parent 55e5e2a commit fe16278
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 21 deletions.
18 changes: 6 additions & 12 deletions src/Engine/Mandarin/Mandarin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {
// NOLINTBEGIN(bugprone-branch-clone)

// the y exceptions fist
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "yuan")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "yuan")) {
secondComponent = BPMF::UE;
thirdComponent = BPMF::AN;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "ying")) {
Expand Down Expand Up @@ -177,8 +176,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {
}

// then we try ZH, CH, SH, R, Z, C, S (in that order)
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "zh")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "zh")) {
firstComponent = BPMF::ZH;
independentConsonant = true;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "ch")) {
Expand All @@ -203,8 +201,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {

// consume exceptions first: (ien, in), (iou, iu), (uen, un), (veng, iong),
// (ven, vn), (uei, ui), ung but longer sequence takes precedence
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "veng")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "veng")) {
secondComponent = BPMF::UE;
thirdComponent = BPMF::ENG;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "iong")) {
Expand Down Expand Up @@ -272,8 +269,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {
}

// then consume the middle component...
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "i")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "i")) {
secondComponent = independentConsonant ? 0 : BPMF::I;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "u")) {
if (firstComponent == BPMF::J || firstComponent == BPMF::Q ||
Expand All @@ -287,8 +283,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {
}

// the vowels, longer sequence takes precedence
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "ang")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "ang")) {
thirdComponent = BPMF::ANG;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "eng")) {
thirdComponent = BPMF::ENG;
Expand Down Expand Up @@ -322,8 +317,7 @@ const BPMF BPMF::FromHanyuPinyin(const std::string& str) {
// NOLINTEND(bugprone-branch-clone)

// at last!
if (false) { // NOLINT(readability-simplify-boolean-expr)
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "1")) {
if (PinyinParseHelper::ConsumePrefix(pinyin, "1")) {
toneComponent = BPMF::Tone1;
} else if (PinyinParseHelper::ConsumePrefix(pinyin, "2")) {
toneComponent = BPMF::Tone2;
Expand Down
9 changes: 0 additions & 9 deletions src/Engine/ParselessPhraseDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,23 +36,14 @@ ParselessPhraseDB::ParselessPhraseDB(
assert(buf != nullptr);
assert(length > 0);

// NOLINTBEGIN(readability-magic-numbers)
if (validate_pragma) {
assert(length > SORTED_PRAGMA_HEADER.length());

std::string_view header(buf, SORTED_PRAGMA_HEADER.length());
assert(header == SORTED_PRAGMA_HEADER);

uint32_t x = 5381;
for (const auto& i : header) {
x = x * 33 + i;
}

assert(x == uint32_t { 3012373384 });

begin_ += header.length();
}
// NOLINTEND(readability-magic-numbers)
}

std::vector<std::string_view> ParselessPhraseDB::findRows(
Expand Down

0 comments on commit fe16278

Please sign in to comment.