Combinations with partial longer match not composed issue resolved
(resolves #6)
This commit is contained in:
parent
f918c49bfd
commit
279537b1f3
@ -37,10 +37,9 @@ void ZRCola::translation_db::Compose(_In_z_count_(inputMax) const wchar_t* input
|
||||
indexComp::size_type compositionsCount = idxComp.size();
|
||||
|
||||
for (size_t i = 0; i < inputMax;) {
|
||||
// Start with the full search area at i-th character.
|
||||
for (size_t l = 0, r = compositionsCount, ii = i, j = 0;; ii++, j++) {
|
||||
if (ii < inputMax) {
|
||||
size_t l_prev = l;
|
||||
// Find the longest matching composition at i-th character.
|
||||
size_t l_match = (size_t)-1;
|
||||
for (size_t l = 0, r = compositionsCount, ii = i, j = 0; ii < inputMax && l < r; ii++, j++) {
|
||||
wchar_t c = input[ii];
|
||||
while (l < r) {
|
||||
// Test the composition in the middle of the search area.
|
||||
@ -74,46 +73,31 @@ void ZRCola::translation_db::Compose(_In_z_count_(inputMax) const wchar_t* input
|
||||
if (s <= c) ll = m + 1; else r = m;
|
||||
}
|
||||
|
||||
const translation &trans = idxComp[l];
|
||||
if (j + 1 == trans.str_len) {
|
||||
// The first composition of the run was a match (thus far). Save it.
|
||||
l_match = l;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (l >= r) {
|
||||
// The search area is empty.
|
||||
if (j && l_prev < compositionsCount && j == idxComp[l_prev].str_len) {
|
||||
// The first composition of the previous run was a match.
|
||||
output += idxComp[l_prev].chr;
|
||||
i = ii;
|
||||
if (j > 1 && map) {
|
||||
if (l_match < compositionsCount) {
|
||||
// The saved composition was an exact match.
|
||||
const translation &trans = idxComp[l_match];
|
||||
output += trans.chr;
|
||||
i += trans.str_len;
|
||||
if (trans.str_len > 1 && map) {
|
||||
// Mapping changed.
|
||||
map->push_back(ZRCola::mapping(output.length(), i));
|
||||
}
|
||||
} else {
|
||||
// The exact match was not found.
|
||||
// The match was not found.
|
||||
output += input[i];
|
||||
i++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
// End of input reached.
|
||||
|
||||
if (l < compositionsCount && j == idxComp[l].str_len) {
|
||||
// The first composition of the previous run was a match.
|
||||
output += idxComp[l].chr;
|
||||
i = ii;
|
||||
if (j > 1 && map) {
|
||||
// Mapping changed.
|
||||
map->push_back(ZRCola::mapping(output.length(), i));
|
||||
}
|
||||
} else {
|
||||
output += input[i];
|
||||
i++;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user