KItinerary

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

KDE's Doxygen guidelines are available online.