File indexing completed on 2024-12-22 04:59:46
0001 /* 0002 SPDX-FileCopyrightText: 2018 Volker Krause <vkrause@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 class QByteArray; 0010 class QString; 0011 class QStringView; 0012 0013 namespace KItinerary { 0014 0015 /** String normalization and comparison utilities. */ 0016 namespace StringUtil 0017 { 0018 /** Strips out diacritics and converts to case-folded form. */ 0019 QString normalize(QStringView str); 0020 0021 /** Assuming both sides are describing the same thing, this tries to find the "better" string. 0022 * That is, prefer the one that didn't lose casing/unicode/etc in previous processing. 0023 */ 0024 QStringView betterString(QStringView lhs, QStringView rhs); 0025 0026 /** Returns how much of the prefix of two given strings are equal, in 0027 * relation to the longer of the two input strings. 0028 */ 0029 float prefixSimilarity(QStringView s1, QStringView s2); 0030 0031 /** Cleans up extra white spaces and XML entities from @p s. */ 0032 QString clean(const QString &s); 0033 0034 /** Transliterate diacritics or other special characters. */ 0035 QString transliterate(QStringView s); 0036 0037 /** Same as QByteArray::startsWith, but ignoring leading whitespaces. */ 0038 bool startsWithIgnoreSpace(const QByteArray &data, const char *pattern); 0039 } 0040 0041 } 0042