Rename member variables
This commit is contained in:
parent
2f567cddc2
commit
385fd34476
|
@ -932,10 +932,10 @@ const BPMF BPMF::FromComposedString(const std::string& str) {
|
||||||
const std::string BPMF::composedString() const {
|
const std::string BPMF::composedString() const {
|
||||||
std::string result;
|
std::string result;
|
||||||
#define APPEND(c) \
|
#define APPEND(c) \
|
||||||
if (m_syllable & c) \
|
if (syllable_ & c) \
|
||||||
result += \
|
result += \
|
||||||
(*BopomofoCharacterMap::SharedInstance().componentToCharacter.find( \
|
(*BopomofoCharacterMap::SharedInstance().componentToCharacter.find( \
|
||||||
m_syllable & c)) \
|
syllable_ & c)) \
|
||||||
.second
|
.second
|
||||||
APPEND(ConsonantMask);
|
APPEND(ConsonantMask);
|
||||||
APPEND(MiddleVowelMask);
|
APPEND(MiddleVowelMask);
|
||||||
|
|
|
@ -36,7 +36,7 @@ class BopomofoSyllable {
|
||||||
public:
|
public:
|
||||||
typedef uint16_t Component;
|
typedef uint16_t Component;
|
||||||
|
|
||||||
explicit BopomofoSyllable(Component syllable = 0) : m_syllable(syllable) {}
|
explicit BopomofoSyllable(Component syllable = 0) : syllable_(syllable) {}
|
||||||
|
|
||||||
BopomofoSyllable(const BopomofoSyllable&) = default;
|
BopomofoSyllable(const BopomofoSyllable&) = default;
|
||||||
BopomofoSyllable(BopomofoSyllable&& another) = default;
|
BopomofoSyllable(BopomofoSyllable&& another) = default;
|
||||||
|
@ -60,37 +60,37 @@ class BopomofoSyllable {
|
||||||
static const BopomofoSyllable FromComposedString(const std::string& str);
|
static const BopomofoSyllable FromComposedString(const std::string& str);
|
||||||
const std::string composedString() const;
|
const std::string composedString() const;
|
||||||
|
|
||||||
void clear() { m_syllable = 0; }
|
void clear() { syllable_ = 0; }
|
||||||
|
|
||||||
bool isEmpty() const { return !m_syllable; }
|
bool isEmpty() const { return !syllable_; }
|
||||||
|
|
||||||
bool hasConsonant() const { return !!(m_syllable & ConsonantMask); }
|
bool hasConsonant() const { return !!(syllable_ & ConsonantMask); }
|
||||||
|
|
||||||
bool hasMiddleVowel() const { return !!(m_syllable & MiddleVowelMask); }
|
bool hasMiddleVowel() const { return !!(syllable_ & MiddleVowelMask); }
|
||||||
bool hasVowel() const { return !!(m_syllable & VowelMask); }
|
bool hasVowel() const { return !!(syllable_ & VowelMask); }
|
||||||
|
|
||||||
bool hasToneMarker() const { return !!(m_syllable & ToneMarkerMask); }
|
bool hasToneMarker() const { return !!(syllable_ & ToneMarkerMask); }
|
||||||
|
|
||||||
Component consonantComponent() const { return m_syllable & ConsonantMask; }
|
Component consonantComponent() const { return syllable_ & ConsonantMask; }
|
||||||
|
|
||||||
Component middleVowelComponent() const {
|
Component middleVowelComponent() const {
|
||||||
return m_syllable & MiddleVowelMask;
|
return syllable_ & MiddleVowelMask;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component vowelComponent() const { return m_syllable & VowelMask; }
|
Component vowelComponent() const { return syllable_ & VowelMask; }
|
||||||
|
|
||||||
Component toneMarkerComponent() const { return m_syllable & ToneMarkerMask; }
|
Component toneMarkerComponent() const { return syllable_ & ToneMarkerMask; }
|
||||||
|
|
||||||
bool operator==(const BopomofoSyllable& another) const {
|
bool operator==(const BopomofoSyllable& another) const {
|
||||||
return m_syllable == another.m_syllable;
|
return syllable_ == another.syllable_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool operator!=(const BopomofoSyllable& another) const {
|
bool operator!=(const BopomofoSyllable& another) const {
|
||||||
return m_syllable != another.m_syllable;
|
return syllable_ != another.syllable_;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isOverlappingWith(const BopomofoSyllable& another) const {
|
bool isOverlappingWith(const BopomofoSyllable& another) const {
|
||||||
#define IOW_SAND(mask) ((m_syllable & mask) && (another.m_syllable & mask))
|
#define IOW_SAND(mask) ((syllable_ & mask) && (another.syllable_ & mask))
|
||||||
return IOW_SAND(ConsonantMask) || IOW_SAND(MiddleVowelMask) ||
|
return IOW_SAND(ConsonantMask) || IOW_SAND(MiddleVowelMask) ||
|
||||||
IOW_SAND(VowelMask) || IOW_SAND(ToneMarkerMask);
|
IOW_SAND(VowelMask) || IOW_SAND(ToneMarkerMask);
|
||||||
#undef IOW_SAND
|
#undef IOW_SAND
|
||||||
|
@ -98,30 +98,30 @@ class BopomofoSyllable {
|
||||||
|
|
||||||
// consonants J, Q, X all require the existence of vowel I or UE
|
// consonants J, Q, X all require the existence of vowel I or UE
|
||||||
bool belongsToJQXClass() const {
|
bool belongsToJQXClass() const {
|
||||||
Component consonant = m_syllable & ConsonantMask;
|
Component consonant = syllable_ & ConsonantMask;
|
||||||
return (consonant == J || consonant == Q || consonant == X);
|
return (consonant == J || consonant == Q || consonant == X);
|
||||||
}
|
}
|
||||||
|
|
||||||
// zi, ci, si, chi, chi, shi, ri
|
// zi, ci, si, chi, chi, shi, ri
|
||||||
bool belongsToZCSRClass() const {
|
bool belongsToZCSRClass() const {
|
||||||
Component consonant = m_syllable & ConsonantMask;
|
Component consonant = syllable_ & ConsonantMask;
|
||||||
return (consonant >= ZH && consonant <= S);
|
return (consonant >= ZH && consonant <= S);
|
||||||
}
|
}
|
||||||
|
|
||||||
Component maskType() const {
|
Component maskType() const {
|
||||||
Component mask = 0;
|
Component mask = 0;
|
||||||
mask |= (m_syllable & ConsonantMask) ? ConsonantMask : 0;
|
mask |= (syllable_ & ConsonantMask) ? ConsonantMask : 0;
|
||||||
mask |= (m_syllable & MiddleVowelMask) ? MiddleVowelMask : 0;
|
mask |= (syllable_ & MiddleVowelMask) ? MiddleVowelMask : 0;
|
||||||
mask |= (m_syllable & VowelMask) ? VowelMask : 0;
|
mask |= (syllable_ & VowelMask) ? VowelMask : 0;
|
||||||
mask |= (m_syllable & ToneMarkerMask) ? ToneMarkerMask : 0;
|
mask |= (syllable_ & ToneMarkerMask) ? ToneMarkerMask : 0;
|
||||||
return mask;
|
return mask;
|
||||||
}
|
}
|
||||||
|
|
||||||
const BopomofoSyllable operator+(const BopomofoSyllable& another) const {
|
const BopomofoSyllable operator+(const BopomofoSyllable& another) const {
|
||||||
Component newSyllable = m_syllable;
|
Component newSyllable = syllable_;
|
||||||
#define OP_SOVER(mask) \
|
#define OP_SOVER(mask) \
|
||||||
if (another.m_syllable & mask) { \
|
if (another.syllable_ & mask) { \
|
||||||
newSyllable = (newSyllable & ~mask) | (another.m_syllable & mask); \
|
newSyllable = (newSyllable & ~mask) | (another.syllable_ & mask); \
|
||||||
}
|
}
|
||||||
OP_SOVER(ConsonantMask);
|
OP_SOVER(ConsonantMask);
|
||||||
OP_SOVER(MiddleVowelMask);
|
OP_SOVER(MiddleVowelMask);
|
||||||
|
@ -133,8 +133,8 @@ 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.syllable_ & mask) { \
|
||||||
m_syllable = (m_syllable & ~mask) | (another.m_syllable & mask); \
|
syllable_ = (syllable_ & ~mask) | (another.syllable_ & mask); \
|
||||||
}
|
}
|
||||||
OPE_SOVER(ConsonantMask);
|
OPE_SOVER(ConsonantMask);
|
||||||
OPE_SOVER(MiddleVowelMask);
|
OPE_SOVER(MiddleVowelMask);
|
||||||
|
@ -146,10 +146,10 @@ class BopomofoSyllable {
|
||||||
|
|
||||||
uint16_t 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 (uint16_t)(m_syllable & ConsonantMask) +
|
return (uint16_t)(syllable_ & ConsonantMask) +
|
||||||
(uint16_t)((m_syllable & MiddleVowelMask) >> 5) * 22 +
|
(uint16_t)((syllable_ & MiddleVowelMask) >> 5) * 22 +
|
||||||
(uint16_t)((m_syllable & VowelMask) >> 7) * 22 * 4 +
|
(uint16_t)((syllable_ & VowelMask) >> 7) * 22 * 4 +
|
||||||
(uint16_t)((m_syllable & ToneMarkerMask) >> 11) * 22 * 4 * 14;
|
(uint16_t)((syllable_ & ToneMarkerMask) >> 11) * 22 * 4 * 14;
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string absoluteOrderString() const {
|
const std::string absoluteOrderString() const {
|
||||||
|
@ -196,7 +196,7 @@ class BopomofoSyllable {
|
||||||
Tone3 = 0x1000, Tone4 = 0x1800, Tone5 = 0x2000;
|
Tone3 = 0x1000, Tone4 = 0x1800, Tone5 = 0x2000;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Component m_syllable;
|
Component syllable_;
|
||||||
};
|
};
|
||||||
|
|
||||||
inline std::ostream& operator<<(std::ostream& stream,
|
inline std::ostream& operator<<(std::ostream& stream,
|
||||||
|
@ -415,32 +415,32 @@ class BopomofoKeyboardLayout {
|
||||||
class BopomofoReadingBuffer {
|
class BopomofoReadingBuffer {
|
||||||
public:
|
public:
|
||||||
explicit BopomofoReadingBuffer(const BopomofoKeyboardLayout* layout)
|
explicit BopomofoReadingBuffer(const BopomofoKeyboardLayout* layout)
|
||||||
: m_layout(layout), m_pinyinMode(false) {
|
: layout_(layout), pinyin_mode_(false) {
|
||||||
if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
|
if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
|
||||||
m_pinyinMode = true;
|
pinyin_mode_ = true;
|
||||||
m_pinyinSequence = "";
|
pinyin_sequence_ = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void setKeyboardLayout(const BopomofoKeyboardLayout* layout) {
|
void setKeyboardLayout(const BopomofoKeyboardLayout* layout) {
|
||||||
m_layout = layout;
|
layout_ = layout;
|
||||||
|
|
||||||
if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
|
if (layout == BopomofoKeyboardLayout::HanyuPinyinLayout()) {
|
||||||
m_pinyinMode = true;
|
pinyin_mode_ = true;
|
||||||
m_pinyinSequence = "";
|
pinyin_sequence_ = "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isValidKey(char k) const {
|
bool isValidKey(char k) const {
|
||||||
if (!m_pinyinMode) {
|
if (!pinyin_mode_) {
|
||||||
return m_layout ? (m_layout->keyToComponents(k)).size() > 0 : false;
|
return layout_ ? (layout_->keyToComponents(k)).size() > 0 : false;
|
||||||
}
|
}
|
||||||
|
|
||||||
char lk = tolower(k);
|
char lk = tolower(k);
|
||||||
if (lk >= 'a' && lk <= 'z') {
|
if (lk >= 'a' && lk <= 'z') {
|
||||||
// if a tone marker is already in place
|
// if a tone marker is already in place
|
||||||
if (m_pinyinSequence.length()) {
|
if (pinyin_sequence_.length()) {
|
||||||
char lastc = m_pinyinSequence[m_pinyinSequence.length() - 1];
|
char lastc = pinyin_sequence_[pinyin_sequence_.length() - 1];
|
||||||
if (lastc >= '2' && lastc <= '5') {
|
if (lastc >= '2' && lastc <= '5') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -449,7 +449,7 @@ class BopomofoReadingBuffer {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_pinyinSequence.length() && (lk >= '2' && lk <= '5')) {
|
if (pinyin_sequence_.length() && (lk >= '2' && lk <= '5')) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -459,72 +459,72 @@ class BopomofoReadingBuffer {
|
||||||
bool combineKey(char k) {
|
bool combineKey(char k) {
|
||||||
if (!isValidKey(k)) return false;
|
if (!isValidKey(k)) return false;
|
||||||
|
|
||||||
if (m_pinyinMode) {
|
if (pinyin_mode_) {
|
||||||
m_pinyinSequence += std::string(1, tolower(k));
|
pinyin_sequence_ += std::string(1, tolower(k));
|
||||||
m_syllable = BPMF::FromHanyuPinyin(m_pinyinSequence);
|
syllable_ = BPMF::FromHanyuPinyin(pinyin_sequence_);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sequence =
|
std::string sequence =
|
||||||
m_layout->keySequenceFromSyllable(m_syllable) + std::string(1, k);
|
layout_->keySequenceFromSyllable(syllable_) + std::string(1, k);
|
||||||
m_syllable = m_layout->syllableFromKeySequence(sequence);
|
syllable_ = layout_->syllableFromKeySequence(sequence);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void clear() {
|
void clear() {
|
||||||
m_pinyinSequence.clear();
|
pinyin_sequence_.clear();
|
||||||
m_syllable.clear();
|
syllable_.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void backspace() {
|
void backspace() {
|
||||||
if (!m_layout) return;
|
if (!layout_) return;
|
||||||
|
|
||||||
if (m_pinyinMode) {
|
if (pinyin_mode_) {
|
||||||
if (m_pinyinSequence.length()) {
|
if (pinyin_sequence_.length()) {
|
||||||
m_pinyinSequence =
|
pinyin_sequence_ =
|
||||||
m_pinyinSequence.substr(0, m_pinyinSequence.length() - 1);
|
pinyin_sequence_.substr(0, pinyin_sequence_.length() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_syllable = BPMF::FromHanyuPinyin(m_pinyinSequence);
|
syllable_ = BPMF::FromHanyuPinyin(pinyin_sequence_);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string sequence = m_layout->keySequenceFromSyllable(m_syllable);
|
std::string sequence = layout_->keySequenceFromSyllable(syllable_);
|
||||||
if (sequence.length()) {
|
if (sequence.length()) {
|
||||||
sequence = sequence.substr(0, sequence.length() - 1);
|
sequence = sequence.substr(0, sequence.length() - 1);
|
||||||
m_syllable = m_layout->syllableFromKeySequence(sequence);
|
syllable_ = layout_->syllableFromKeySequence(sequence);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isEmpty() const { return m_syllable.isEmpty(); }
|
bool isEmpty() const { return syllable_.isEmpty(); }
|
||||||
|
|
||||||
const std::string composedString() const {
|
const std::string composedString() const {
|
||||||
if (m_pinyinMode) {
|
if (pinyin_mode_) {
|
||||||
return m_pinyinSequence;
|
return pinyin_sequence_;
|
||||||
}
|
}
|
||||||
|
|
||||||
return m_syllable.composedString();
|
return syllable_.composedString();
|
||||||
}
|
}
|
||||||
|
|
||||||
const BPMF syllable() const { return m_syllable; }
|
const BPMF syllable() const { return syllable_; }
|
||||||
|
|
||||||
const std::string standardLayoutQueryString() const {
|
const std::string standardLayoutQueryString() const {
|
||||||
return BopomofoKeyboardLayout::StandardLayout()->keySequenceFromSyllable(
|
return BopomofoKeyboardLayout::StandardLayout()->keySequenceFromSyllable(
|
||||||
m_syllable);
|
syllable_);
|
||||||
}
|
}
|
||||||
|
|
||||||
const std::string absoluteOrderQueryString() const {
|
const std::string absoluteOrderQueryString() const {
|
||||||
return m_syllable.absoluteOrderString();
|
return syllable_.absoluteOrderString();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool hasToneMarker() const { return m_syllable.hasToneMarker(); }
|
bool hasToneMarker() const { return syllable_.hasToneMarker(); }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
const BopomofoKeyboardLayout* m_layout;
|
const BopomofoKeyboardLayout* layout_;
|
||||||
BPMF m_syllable;
|
BPMF syllable_;
|
||||||
|
|
||||||
bool m_pinyinMode;
|
bool pinyin_mode_;
|
||||||
std::string m_pinyinSequence;
|
std::string pinyin_sequence_;
|
||||||
};
|
};
|
||||||
} // namespace Mandarin
|
} // namespace Mandarin
|
||||||
} // namespace Formosa
|
} // namespace Formosa
|
||||||
|
|
Loading…
Reference in New Issue