Refactor correction.cpp
Change-Id: I1275496e3e7d7124494994d3c52730ec8afdfad3
This commit is contained in:
parent
6929b0dd97
commit
b9d09e73e0
1 changed files with 95 additions and 95 deletions
|
@ -210,11 +210,14 @@ Correction::CorrectionType Correction::processSkipChar(
|
||||||
|
|
||||||
Correction::CorrectionType Correction::processCharAndCalcState(
|
Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
const int32_t c, const bool isTerminal) {
|
const int32_t c, const bool isTerminal) {
|
||||||
CorrectionType currentStateType = NOT_ON_TERMINAL;
|
|
||||||
|
if (mNeedsToTraverseAllNodes || isQuote(c)) {
|
||||||
|
return processSkipChar(c, isTerminal);
|
||||||
|
}
|
||||||
|
|
||||||
if (mExcessivePos >= 0) {
|
if (mExcessivePos >= 0) {
|
||||||
if (mExcessiveCount == 0 && mExcessivePos < mOutputIndex) {
|
if (mExcessiveCount == 0 && mExcessivePos < mOutputIndex) {
|
||||||
++mExcessivePos;
|
mExcessivePos = mOutputIndex;
|
||||||
}
|
}
|
||||||
if (mExcessivePos < mInputLength - 1) {
|
if (mExcessivePos < mInputLength - 1) {
|
||||||
mExceeding = mExcessivePos == mInputIndex;
|
mExceeding = mExcessivePos == mInputIndex;
|
||||||
|
@ -226,23 +229,20 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
if (DEBUG_DICT) {
|
if (DEBUG_DICT) {
|
||||||
assert(mSkipPos == mOutputIndex - 1);
|
assert(mSkipPos == mOutputIndex - 1);
|
||||||
}
|
}
|
||||||
++mSkipPos;
|
mSkipPos = mOutputIndex;
|
||||||
}
|
}
|
||||||
mSkipping = mSkipPos == mOutputIndex;
|
mSkipping = mSkipPos == mOutputIndex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mTransposedPos >= 0) {
|
if (mTransposedPos >= 0) {
|
||||||
if (mTransposedCount == 0 && mTransposedPos < mOutputIndex) {
|
if (mTransposedCount == 0 && mTransposedPos < mOutputIndex) {
|
||||||
++mTransposedPos;
|
mTransposedPos = mOutputIndex;
|
||||||
}
|
}
|
||||||
if (mTransposedPos < mInputLength - 1) {
|
if (mTransposedPos < mInputLength - 1) {
|
||||||
mTransposing = mInputIndex == mTransposedPos;
|
mTransposing = mInputIndex == mTransposedPos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mNeedsToTraverseAllNodes || isQuote(c)) {
|
|
||||||
return processSkipChar(c, isTerminal);
|
|
||||||
} else {
|
|
||||||
bool secondTransposing = false;
|
bool secondTransposing = false;
|
||||||
if (mTransposedCount % 2 == 1) {
|
if (mTransposedCount % 2 == 1) {
|
||||||
if (mProximityInfo->getMatchedProximityId(mInputIndex - 1, c, false)
|
if (mProximityInfo->getMatchedProximityId(mInputIndex - 1, c, false)
|
||||||
|
@ -262,11 +262,11 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
// TODO: sum counters
|
// TODO: sum counters
|
||||||
const bool checkProximityChars =
|
const bool checkProximityChars =
|
||||||
!(mSkippedCount > 0 || mExcessivePos >= 0 || mTransposedPos >= 0);
|
!(mSkippedCount > 0 || mExcessivePos >= 0 || mTransposedPos >= 0);
|
||||||
// TODO: do not check if second transposing
|
const int matchedProximityCharId = secondTransposing
|
||||||
const int matchedProximityCharId = mProximityInfo->getMatchedProximityId(
|
? ProximityInfo::SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR
|
||||||
mInputIndex, c, checkProximityChars);
|
: mProximityInfo->getMatchedProximityId(mInputIndex, c, checkProximityChars);
|
||||||
|
|
||||||
if (!secondTransposing && ProximityInfo::UNRELATED_CHAR == matchedProximityCharId) {
|
if (ProximityInfo::UNRELATED_CHAR == matchedProximityCharId) {
|
||||||
if (mInputIndex - 1 < mInputLength && (mExceeding || mTransposing)
|
if (mInputIndex - 1 < mInputLength && (mExceeding || mTransposing)
|
||||||
&& mProximityInfo->getMatchedProximityId(mInputIndex + 1, c, false)
|
&& mProximityInfo->getMatchedProximityId(mInputIndex + 1, c, false)
|
||||||
== ProximityInfo::SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR) {
|
== ProximityInfo::SAME_OR_ACCENTED_OR_CAPITALIZED_CHAR) {
|
||||||
|
@ -315,11 +315,7 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
// TODO: Decrement mExcessiveCount if next char is matched word.
|
// TODO: Decrement mExcessiveCount if next char is matched word.
|
||||||
++mExcessiveCount;
|
++mExcessiveCount;
|
||||||
}
|
}
|
||||||
if (isSameAsUserTypedLength && isTerminal) {
|
|
||||||
mTerminalInputIndex = mInputIndex;
|
|
||||||
mTerminalOutputIndex = mOutputIndex;
|
|
||||||
currentStateType = ON_TERMINAL;
|
|
||||||
}
|
|
||||||
// Start traversing all nodes after the index exceeds the user typed length
|
// Start traversing all nodes after the index exceeds the user typed length
|
||||||
if (isSameAsUserTypedLength) {
|
if (isSameAsUserTypedLength) {
|
||||||
startToTraverseAllNodes();
|
startToTraverseAllNodes();
|
||||||
|
@ -331,12 +327,16 @@ Correction::CorrectionType Correction::processCharAndCalcState(
|
||||||
// characters to input; the other branch is not matching them but searching for
|
// characters to input; the other branch is not matching them but searching for
|
||||||
// completions, this is why it does not have to do it.
|
// completions, this is why it does not have to do it.
|
||||||
incrementInputIndex();
|
incrementInputIndex();
|
||||||
}
|
|
||||||
|
|
||||||
// Also, the next char is one "virtual node" depth more than this char.
|
// Also, the next char is one "virtual node" depth more than this char.
|
||||||
incrementOutputIndex();
|
incrementOutputIndex();
|
||||||
|
|
||||||
return currentStateType;
|
if (isSameAsUserTypedLength && isTerminal) {
|
||||||
|
mTerminalInputIndex = mInputIndex - 1;
|
||||||
|
mTerminalOutputIndex = mOutputIndex - 1;
|
||||||
|
return ON_TERMINAL;
|
||||||
|
} else {
|
||||||
|
return NOT_ON_TERMINAL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Correction::~Correction() {
|
Correction::~Correction() {
|
||||||
|
|
Loading…
Reference in a new issue