Fix most cpplint warnings

This commit is contained in:
Lukhnos Liu 2022-01-31 22:21:18 -08:00
parent f0222c023d
commit a455aef587
1 changed files with 28 additions and 23 deletions

View File

@ -38,8 +38,9 @@ namespace Mandarin {
class BopomofoSyllable { class BopomofoSyllable {
public: public:
typedef unsigned int Component; typedef uint16_t Component;
BopomofoSyllable(Component syllable = 0) : m_syllable(syllable) {}
explicit BopomofoSyllable(Component syllable = 0) : m_syllable(syllable) {}
BopomofoSyllable(const BopomofoSyllable&) = default; BopomofoSyllable(const BopomofoSyllable&) = default;
BopomofoSyllable(BopomofoSyllable&& another) = default; BopomofoSyllable(BopomofoSyllable&& another) = default;
@ -123,8 +124,9 @@ class BopomofoSyllable {
const BopomofoSyllable operator+(const BopomofoSyllable& another) const { const BopomofoSyllable operator+(const BopomofoSyllable& another) const {
Component newSyllable = m_syllable; Component newSyllable = m_syllable;
#define OP_SOVER(mask) \ #define OP_SOVER(mask) \
if (another.m_syllable & mask) \ if (another.m_syllable & mask) { \
newSyllable = (newSyllable & ~mask) | (another.m_syllable & mask) newSyllable = (newSyllable & ~mask) | (another.m_syllable & mask); \
}
OP_SOVER(ConsonantMask); OP_SOVER(ConsonantMask);
OP_SOVER(MiddleVowelMask); OP_SOVER(MiddleVowelMask);
OP_SOVER(VowelMask); OP_SOVER(VowelMask);
@ -135,8 +137,9 @@ class BopomofoSyllable {
BopomofoSyllable& operator+=(const BopomofoSyllable& another) { BopomofoSyllable& operator+=(const BopomofoSyllable& another) {
#define OPE_SOVER(mask) \ #define OPE_SOVER(mask) \
if (another.m_syllable & mask) \ if (another.m_syllable & mask) { \
m_syllable = (m_syllable & ~mask) | (another.m_syllable & mask) m_syllable = (m_syllable & ~mask) | (another.m_syllable & mask); \
}
OPE_SOVER(ConsonantMask); OPE_SOVER(ConsonantMask);
OPE_SOVER(MiddleVowelMask); OPE_SOVER(MiddleVowelMask);
OPE_SOVER(VowelMask); OPE_SOVER(VowelMask);
@ -145,26 +148,26 @@ class BopomofoSyllable {
return *this; return *this;
} }
short absoluteOrder() const { uint16_t absoluteOrder() const {
// turn BPMF syllable into a 4*14*4*22 number // turn BPMF syllable into a 4*14*4*22 number
return (short)(m_syllable & ConsonantMask) + return (uint16_t)(m_syllable & ConsonantMask) +
(short)((m_syllable & MiddleVowelMask) >> 5) * 22 + (uint16_t)((m_syllable & MiddleVowelMask) >> 5) * 22 +
(short)((m_syllable & VowelMask) >> 7) * 22 * 4 + (uint16_t)((m_syllable & VowelMask) >> 7) * 22 * 4 +
(short)((m_syllable & ToneMarkerMask) >> 11) * 22 * 4 * 14; (uint16_t)((m_syllable & ToneMarkerMask) >> 11) * 22 * 4 * 14;
} }
const std::string absoluteOrderString() const { const std::string absoluteOrderString() const {
// 5*14*4*22 = 6160, we use a 79*79 encoding to represent that // 5*14*4*22 = 6160, we use a 79*79 encoding to represent that
short order = absoluteOrder(); uint16_t order = absoluteOrder();
char low = 48 + (char)(order % 79); char low = 48 + static_cast<char>(order % 79);
char high = 48 + (char)(order / 79); char high = 48 + static_cast<char>(order / 79);
std::string result(2, ' '); std::string result(2, ' ');
result[0] = low; result[0] = low;
result[1] = high; result[1] = high;
return result; return result;
} }
static BopomofoSyllable FromAbsoluteOrder(short order) { static BopomofoSyllable FromAbsoluteOrder(uint16_t order) {
return BopomofoSyllable((order % 22) | ((order / 22) % 4) << 5 | return BopomofoSyllable((order % 22) | ((order / 22) % 4) << 5 |
((order / (22 * 4)) % 14) << 7 | ((order / (22 * 4)) % 14) << 7 |
((order / (22 * 4 * 14)) % 5) << 11); ((order / (22 * 4 * 14)) % 5) << 11);
@ -173,7 +176,8 @@ class BopomofoSyllable {
static BopomofoSyllable FromAbsoluteOrderString(const std::string& str) { static BopomofoSyllable FromAbsoluteOrderString(const std::string& str) {
if (str.length() != 2) return BopomofoSyllable(); if (str.length() != 2) return BopomofoSyllable();
return FromAbsoluteOrder((short)(str[1] - 48) * 79 + (short)(str[0] - 48)); return FromAbsoluteOrder((uint16_t)(str[1] - 48) * 79 +
(uint16_t)(str[0] - 48));
} }
friend std::ostream& operator<<(std::ostream& stream, friend std::ostream& operator<<(std::ostream& stream,
@ -322,14 +326,15 @@ class BopomofoKeyboardLayout {
// the nasty issue of only one char in the buffer // the nasty issue of only one char in the buffer
if (iter == sequence.begin() && iter + 1 == sequence.end()) { if (iter == sequence.begin() && iter + 1 == sequence.end()) {
if (head.hasVowel() || follow.hasToneMarker() || if (head.hasVowel() || follow.hasToneMarker() ||
head.belongsToZCSRClass()) head.belongsToZCSRClass()) {
syllable += head; syllable += head;
else { } else {
if (follow.hasVowel() || ending.hasToneMarker()) if (follow.hasVowel() || ending.hasToneMarker()) {
syllable += follow; syllable += follow;
else } else {
syllable += ending; syllable += ending;
} }
}
continue; continue;
} }
@ -413,7 +418,7 @@ class BopomofoKeyboardLayout {
class BopomofoReadingBuffer { class BopomofoReadingBuffer {
public: public:
BopomofoReadingBuffer(const BopomofoKeyboardLayout* layout) explicit BopomofoReadingBuffer(const BopomofoKeyboardLayout* layout)
: m_layout(layout), m_pinyinMode(false) { : m_layout(layout), m_pinyinMode(false) {
if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) { if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
m_pinyinMode = true; m_pinyinMode = true;