Refactor correction.cpp

Change-Id: I1275496e3e7d7124494994d3c52730ec8afdfad3
main
satok 2011-08-19 17:27:46 +09:00
parent 6929b0dd97
commit b9d09e73e0
1 changed files with 95 additions and 95 deletions

View File

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