KItinerary

alphaid.cpp
1/*
2 SPDX-FileCopyrightText: 2019 Volker Krause <vkrause@kde.org>
3
4 SPDX-License-Identifier: LGPL-2.0-or-later
5*/
6
7#include "alphaid.h"
8
9using namespace KItinerary;
10
11uint32_t KnowledgeDb::Internal::alphaIdFromString(QStringView s, int size)
12{
13 uint32_t res = {};
14 if (size != s.size()) {
15 return res;
16 }
17
18 for (int i = 0; i < size; ++i) {
19 const auto c = s[i];
20 if (c.row() != 0 || (c.cell() < 'A' || c.cell() > 'Z')) {
21 return {};
22 }
23 res |= (c.cell() - '@') << (5 * (size - i - 1));
24 }
25
26 return res;
27}
28
29QString KnowledgeDb::Internal::alphaIdToString(uint32_t id, int size)
30{
31 if (id == 0) {
32 return {};
33 }
34
35 QString s;
36 s.reserve(size);
37 for (int i = 0; i < size; ++i) {
38 const auto shift = 5 * (size - i - 1);
39 const auto mask = 31;
40 const auto c = (id & (mask << shift)) >> shift;
41 s.push_back(QLatin1Char(c + '@'));
42 }
43
44 return s;
45}
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
void push_back(QChar ch)
void reserve(qsizetype size)
qsizetype size() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 4 2024 16:28:48 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.