1/*
2 This file is part of the KFileMetaData project
3 SPDX-FileCopyrightText: 2024 Stefan BrĂ¼ns <stefan.bruens@rwth-aachen.de>
4
5 SPDX-License-Identifier: LGPL-2.1-only
6*/
7
8namespace {
9
10class LcIdentifierName
11{
12 // A proxy class for fast case-insensitive lookup of
13 // keys in a QHash
14 //
15 // Pre-condition: Uppercase letters (QChar::isUpper) must
16 // trivially map to their lowercase counterpart. This
17 // is the case for all ASCII codepoints.
18public:
19 LcIdentifierName(const QStringView _name) : name(_name) {};
20 QStringView name;
21};
22
23constexpr QChar trivialToLower(const QChar &c) {
24 if (c.isUpper()) {
25 return QChar::fromLatin1(c: c.toLatin1() ^ ('a' ^ 'A'));
26 }
27 return c;
28}
29
30inline bool operator==(const LcIdentifierName &a, const LcIdentifierName &b)
31{
32 if (a.name.size() != b.name.size()) {
33 return false;
34 }
35 for (int i = 0; i < a.name.size(); i++) {
36 if ((a.name[i] != b.name[i]) && (trivialToLower(c: a.name[i]) != trivialToLower(c: b.name[i]))) {
37 return false;
38 }
39 }
40 return true;
41}
42
43inline size_t qHash(const LcIdentifierName &key, size_t seed = 0)
44{
45 size_t val = seed;
46 for (const auto& c : key.name) {
47 val ^= qHash(key: trivialToLower(c));
48 }
49 return val;
50}
51
52}
53
54

source code of kfilemetadata/src/icnamematch_p.h