Removes the usage of OVUTF8Helper in the key handler.

This commit is contained in:
zonble 2022-02-02 17:58:13 +08:00
parent 8e1e3d184b
commit 4743889e2f
2 changed files with 10 additions and 5 deletions

View File

@ -38,7 +38,6 @@ using namespace std;
using namespace Formosa::Mandarin; using namespace Formosa::Mandarin;
using namespace Formosa::Gramambular; using namespace Formosa::Gramambular;
using namespace McBopomofo; using namespace McBopomofo;
using namespace OpenVanilla;
InputMode InputModeBopomofo = @"org.openvanilla.inputmethod.McBopomofo.Bopomofo"; InputMode InputModeBopomofo = @"org.openvanilla.inputmethod.McBopomofo.Bopomofo";
InputMode InputModePlainBopomofo = @"org.openvanilla.inputmethod.McBopomofo.PlainBopomofo"; InputMode InputModePlainBopomofo = @"org.openvanilla.inputmethod.McBopomofo.PlainBopomofo";
@ -1143,12 +1142,12 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
for (vector<NodeAnchor>::iterator wi = _walkedNodes.begin(), we = _walkedNodes.end(); wi != we; ++wi) { for (vector<NodeAnchor>::iterator wi = _walkedNodes.begin(), we = _walkedNodes.end(); wi != we; ++wi) {
if ((*wi).node) { if ((*wi).node) {
string nodeStr = (*wi).node->currentKeyValue().value; string nodeStr = (*wi).node->currentKeyValue().value;
vector<string> codepoints = OVUTF8Helper::SplitStringByCodePoint(nodeStr);
size_t codepointCount = codepoints.size();
NSString *valueString = [NSString stringWithUTF8String:nodeStr.c_str()]; NSString *valueString = [NSString stringWithUTF8String:nodeStr.c_str()];
[composingBuffer appendString:valueString]; [composingBuffer appendString:valueString];
NSArray *splited = [valueString split];
NSInteger codepointCount = splited.count;
// this re-aligns the cursor index in the composed string // this re-aligns the cursor index in the composed string
// (the actual cursor on the screen) with the builder's logical // (the actual cursor on the screen) with the builder's logical
// cursor (reading) cursor; each built node has a "spanning length" // cursor (reading) cursor; each built node has a "spanning length"
@ -1162,7 +1161,7 @@ static NSString *const kGraphVizOutputfile = @"/tmp/McBopomofo-visualization.dot
} else { } else {
if (codepointCount == spanningLength) { if (codepointCount == spanningLength) {
for (size_t i = 0; i < codepointCount && readingCursorIndex < builderCursorIndex; i++) { for (size_t i = 0; i < codepointCount && readingCursorIndex < builderCursorIndex; i++) {
composedStringCursorIndex += [[NSString stringWithUTF8String:codepoints[i].c_str()] length]; composedStringCursorIndex += [splited[i] length];
readingCursorIndex++; readingCursorIndex++;
} }
} else { } else {

View File

@ -70,4 +70,10 @@ extension NSString {
@objc var count: Int { @objc var count: Int {
(self as String).count (self as String).count
} }
@objc var split: [NSString] {
Array(self as String).map {
NSString(string: String($0))
}
}
} }