KItinerary

token.cpp
1/*
2 SPDX-FileCopyrightText: 2018-2022 Volker Krause <vkrause@kde.org>
3 SPDX-License-Identifier: LGPL-2.0-or-later
4*/
5
6#include "token.h"
7
8#include <QStringView>
9#include <QVariant>
10
11using namespace KItinerary;
12
14{
15 if (token.startsWith(QLatin1StringView("qrcode"), Qt::CaseInsensitive)) {
16 return QRCode;
17 } else if (token.startsWith(QLatin1StringView("aztec"),
19 return AztecCode;
20 } else if (token.startsWith(QLatin1StringView("barcode128:"),
22 return Code128;
23 } else if (token.startsWith(QLatin1StringView("datamatrix:"),
25 return DataMatrix;
26 } else if (token.startsWith(QLatin1StringView("pdf417"),
28 return PDF417;
29 } else if (token.startsWith(QLatin1StringView("code39:"),
31 return Code39;
32 } else if (token.startsWith(QLatin1StringView("ean13:"),
34 return EAN13;
35 } else if (token.startsWith(QLatin1StringView("http"), Qt::CaseInsensitive)) {
36 return Url;
37 }
38 return Unknown;
39}
40
42{
43 if (token.startsWith(QLatin1StringView("qrcode:"), Qt::CaseInsensitive)) {
44 return token.mid(7);
45 }
46 if (token.startsWith(QLatin1StringView("qrcodebin:"), Qt::CaseInsensitive)) {
47 return QByteArray::fromBase64(token.mid(10).toLatin1());
48 } else if (token.startsWith(QLatin1StringView("azteccode:"),
50 return token.mid(10);
51 } else if (token.startsWith(QLatin1StringView("aztecbin:"),
53 return QByteArray::fromBase64(QStringView(token).mid(9).toLatin1());
54 } else if (token.startsWith(QLatin1StringView("barcode128:"),
56 return token.mid(11);
57 } else if (token.startsWith(QLatin1StringView("datamatrix:"),
59 return token.mid(11);
60 } else if (token.startsWith(QLatin1StringView("pdf417:"),
62 return token.mid(7);
63 } else if (token.startsWith(QLatin1StringView("pdf417bin:"),
65 return QByteArray::fromBase64(QStringView(token).mid(10).toLatin1());
66 } else if (token.startsWith(QLatin1StringView("ean13:"),
68 return token.mid(6);
69 } else if (token.startsWith(QLatin1StringView("code39:"),
71 return token.mid(7);
72 }
73
74 // Qt 6 only does shallow isNull checks, so make sure empty strings produce empty variants
75 return token.isEmpty() ? QVariant() : QVariant(token);
76}
77
78#include "moc_token.cpp"
static QVariant tokenData(const QString &token)
Determine token content for the given token.
Definition token.cpp:41
TokenType
Token format.
Definition token.h:28
@ Unknown
Unknown or empty ticket token.
Definition token.h:29
@ PDF417
A PDF417 barcode.
Definition token.h:35
@ DataMatrix
A DataMatrix barcode.
Definition token.h:34
@ Code39
A Code 39 barcode.
Definition token.h:36
@ Code128
Code 128 barcode.
Definition token.h:33
@ AztecCode
Aztec code. Binary content is handled transparently by tokenData().
Definition token.h:32
@ EAN13
A EAN13 barcode.
Definition token.h:37
@ QRCode
QR code.
Definition token.h:31
@ Url
A download URL, if shown in a barcode its format can be determined by the application.
Definition token.h:30
static TokenType tokenType(QStringView token)
Determine token type for the given token.
Definition token.cpp:13
Classes for reservation/travel data models, data extraction and data augmentation.
Definition berelement.h:17
QByteArray fromBase64(const QByteArray &base64, Base64Options options)
bool isEmpty() const const
QString mid(qsizetype position, qsizetype n) const const
bool startsWith(QChar c, Qt::CaseSensitivity cs) const const
QByteArray toLatin1() const const
bool startsWith(QChar ch) const const
CaseInsensitive
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Mon Nov 18 2024 12:09:58 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.