Commit 6ef5a789 authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Synchronize normalize method

parent 9826dea3
Pipeline #147196 passed with stage
in 2 minutes and 21 seconds
......@@ -7,28 +7,28 @@
#include "textutil.h"
// code from kitinerary/src/lib/stringutil.cpp
QChar TextUtil::normalize(QChar c)
{
// case folding
const auto n = c.toCaseFolded();
// if the character has a canonical decomposition use that and skip the
// combining diacritic markers following it
// see https://en.wikipedia.org/wiki/Unicode_equivalence
// see https://en.wikipedia.org/wiki/Combining_character
if (n.decompositionTag() == QChar::Canonical) {
return n.decomposition().at(0);
}
return n;
}
QString TextUtil::normalize(QStringView str)
{
QString out;
out.reserve(str.size());
for (const auto c : str) {
out.push_back(normalize(c));
// case folding
const auto n = c.toCaseFolded();
// if the character has a canonical decomposition use that and skip the
// combining diacritic markers following it
// see https://en.wikipedia.org/wiki/Unicode_equivalence
// see https://en.wikipedia.org/wiki/Combining_character
if (n.decompositionTag() == QChar::Canonical) {
out.push_back(n.decomposition().at(0));
}
// handle compatibility compositions such as ligatures
// see https://en.wikipedia.org/wiki/Unicode_compatibility_characters
else if (n.decompositionTag() == QChar::Compat && n.isLetter() && n.script() == QChar::Script_Latin) {
out.append(n.decomposition());
} else {
out.push_back(n);
}
}
return out;
}
......@@ -10,5 +10,4 @@
namespace TextUtil
{
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
};
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment