Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qndefnfcurirecord.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qndefnfcurirecord.h"
5
6#include <QtCore/QString>
7#include <QtCore/QUrl>
8
9#include <QtCore/QDebug>
10
12
35static const char * const abbreviations[] = {
36 0,
37 "http://www.",
38 "https://www.",
39 "http://",
40 "https://",
41 "tel:",
42 "mailto:",
43 "ftp://anonymous:anonymous@",
44 "ftp://ftp.",
45 "ftps://",
46 "sftp://",
47 "smb://",
48 "nfs://",
49 "ftp://",
50 "dav://",
51 "news:",
52 "telnet://",
53 "imap:",
54 "rtsp://",
55 "urn:",
56 "pop:",
57 "sip:",
58 "sips:",
59 "tftp:",
60 "btspp://",
61 "btl2cap://",
62 "btgoep://",
63 "tcpobex://",
64 "irdaobex://",
65 "file://",
66 "urn:epc:id:",
67 "urn:epc:tag:",
68 "urn:epc:pat:",
69 "urn:epc:raw:",
70 "urn:epc:",
71 "urn:nfc:",
72};
73
77QUrl QNdefNfcUriRecord::uri() const
78{
80
81 if (p.isEmpty())
82 return QUrl();
83
84 quint8 code = p.at(0);
85 if (code >= sizeof(abbreviations) / sizeof(*abbreviations))
86 code = 0;
87 p.remove(0, 1);
88 if (const char *abbreviation = abbreviations[code])
89 p.insert(0, abbreviation);
90 return QUrl(QString::fromUtf8(p));
91}
92
97{
98 int abbrevs = sizeof(abbreviations) / sizeof(*abbreviations);
99
100 for (int i = 1; i < abbrevs; ++i) {
102 QByteArray p(1, i);
103
104 p += uri.toString().mid(qstrlen(abbreviations[i])).toUtf8();
105
106 setPayload(p);
107
108 return;
109 }
110 }
111
112 QByteArray p(1, 0);
113 p += uri.toString().toUtf8();
114
115 setPayload(p);
116}
117
\inmodule QtCore
Definition qbytearray.h:57
void setUri(const QUrl &uri)
Sets the URI of this URI record to uri.
void setPayload(const QByteArray &payload)
Sets the payload of the NDEF record to payload.
QByteArray payload() const
Returns the payload of the NDEF record.
bool startsWith(const QString &s, Qt::CaseSensitivity cs=Qt::CaseSensitive) const
Returns true if the string starts with s; otherwise returns false.
Definition qstring.cpp:5455
QString mid(qsizetype position, qsizetype n=-1) const &
Definition qstring.cpp:5300
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:6018
const QChar at(qsizetype i) const
Returns the character at the given index position in the string.
Definition qstring.h:1226
QString & insert(qsizetype i, QChar c)
Definition qstring.cpp:3132
QString & remove(qsizetype i, qsizetype len)
Removes n characters from the string, starting at the given position index, and returns a reference t...
Definition qstring.cpp:3466
QByteArray toUtf8() const &
Definition qstring.h:634
\inmodule QtCore
Definition qurl.h:94
QString toString(FormattingOptions options=FormattingOptions(PrettyDecoded)) const
Returns a string representation of the URL.
Definition qurl.cpp:2831
Combined button and popup list for selecting options.
size_t qstrlen(const char *str)
static const char *const abbreviations[]
GLfloat GLfloat p
[1]
QLatin1StringView QLatin1String
Definition qstringfwd.h:31
unsigned char quint8
Definition qtypes.h:46