Commit f16f822f authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Prepare to search diacritic word

parent f238c06f
Pipeline #138271 passed with stages
in 9 minutes and 28 seconds
......@@ -36,3 +36,30 @@ int FindUtils::replaceAll(QTextDocument *document, const TextFindWidget *findWid
c.endEditBlock();
return count;
}
// code from kitinerary/src/lib/stringutil.cpp
QChar FindUtils::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 FindUtils::normalize(QStringView str)
{
QString out;
out.reserve(str.size());
for (const auto c : str) {
out.push_back(normalize(c));
}
return out;
}
......@@ -6,8 +6,9 @@
#pragma once
#include <QChar>
#include <QStringView>
#include <qglobal.h>
class QTextDocument;
namespace KPIMTextEdit
......@@ -24,6 +25,8 @@ namespace FindUtils
* @return number of replacements done
*/
Q_REQUIRED_RESULT int replaceAll(QTextDocument *document, const TextFindWidget *findWidget, const TextReplaceWidget *replaceWidget);
Q_REQUIRED_RESULT QString normalize(QStringView str);
Q_REQUIRED_RESULT QChar normalize(QChar c);
}
} // namespace KPIMTextEdit
Markdown is supported
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