Commit 437a98ed authored by Laurent Montel's avatar Laurent Montel 😁
Browse files

Add normalize string

parent 11bc34aa
Pipeline #148084 passed with stage
in 1 minute and 52 seconds
......@@ -33,7 +33,11 @@ target_sources(akonadi_indexing_agent PRIVATE
scheduler.h
collectionindexingjob.h
index.h
collectionupdatejob.h)
collectionupdatejob.h
stringutil.h
stringutil.cpp
)
ecm_qt_declare_logging_category(akonadi_indexing_agent HEADER akonadi_indexer_agent_debug.h IDENTIFIER AKONADI_INDEXER_AGENT_LOG CATEGORY_NAME org.kde.pim.akonadi_indexer_agent
DESCRIPTION "akonadisearch (akonadi indexer agent)"
......
/*
* SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*
*/
#include "stringutil.h"
// code from kitinerary/src/lib/stringutil.cpp
QString StringUtil::normalize(QStringView str)
{
QString out;
out.reserve(str.size());
for (const auto c : str) {
// 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;
}
/*
* SPDX-FileCopyrightText: 2022 Laurent Montel <montel@kde.org>
*
* SPDX-License-Identifier: GPL-2.0-only OR GPL-3.0-only OR LicenseRef-KDE-Accepted-GPL
*
*/
#pragma once
#include <QString>
namespace StringUtil
{
Q_REQUIRED_RESULT QString normalize(QStringView str);
};
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