Alpha 1.0.11: emoji parsing fixed.

We should count emoji length correctly in cases we have a partial
match for a longer one, but not a full match. If we start reading
the next characters but don't find a full emoji there we need to
have a correct length of a previously found emoji saved already.
This commit is contained in:
John Preston 2017-02-17 21:57:21 +03:00
parent d259656e89
commit b7c4e867e8
2 changed files with 240 additions and 228 deletions

View File

@ -520,6 +520,7 @@ bool Generator::writeFindFromDictionary(const std::map<QString, int, std::greate
auto checkTypes = QVector<UsedCheckType>();
auto chars = QString();
auto tabsUsed = 1;
auto lengthsCounted = std::map<QString, bool>();
auto writeSkipPostfix = [this, &tabs, skipPostfixes](int tabsCount) {
if (skipPostfixes) {
@ -573,6 +574,14 @@ bool Generator::writeFindFromDictionary(const std::map<QString, int, std::greate
auto weContinueOldSwitch = finishChecksTillKey(key);
while (chars.size() != key.size()) {
auto checking = chars.size();
auto partialKey = key.mid(0, checking);
if (dictionary.find(partialKey) != dictionary.cend()) {
if (lengthsCounted.find(partialKey) == lengthsCounted.cend()) {
lengthsCounted.insert(std::make_pair(partialKey, true));
source_->stream() << tabs(tabsUsed) << "if (outLength) *outLength = (ch - start);\n";
}
}
auto keyChar = key[checking];
auto keyCharString = "0x" + QString::number(keyChar.unicode(), 16);
auto usedIfForCheck = !weContinueOldSwitch && canUseIfForCheck(i, e, checking);
@ -591,7 +600,10 @@ bool Generator::writeFindFromDictionary(const std::map<QString, int, std::greate
writeSkipPostfix(++tabsUsed);
chars.push_back(keyChar);
}
source_->stream() << tabs(tabsUsed) << "if (outLength) *outLength = (ch - start);\n";
if (lengthsCounted.find(key) == lengthsCounted.cend()) {
lengthsCounted.insert(std::make_pair(key, true));
source_->stream() << tabs(tabsUsed) << "if (outLength) *outLength = (ch - start);\n";
}
// While IsReplaceEdge() currently is always true we just return the value.
//source_->stream() << tabs(1 + chars.size()) << "if (ch + " << chars.size() << " == end || IsReplaceEdge(*(ch + " << chars.size() << ")) || (ch + " << chars.size() << ")->unicode() == ' ') {\n";

File diff suppressed because it is too large Load Diff