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
qndefnfctextrecord.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
5
6#include <QtCore/QStringConverter>
7#include <QtCore/QLocale>
8
10
46QString QNdefNfcTextRecord::locale() const
47{
48 const QByteArray p = payload();
49
50 if (p.isEmpty())
51 return QString();
52
53 quint8 status = p.at(0);
54
55 quint8 codeLength = status & 0x3f;
56
57 return QString::fromLatin1(p.constData() + 1, codeLength);
58}
59
64{
66
67 quint8 status = p.isEmpty() ? 0 : p.at(0);
68
69 quint8 codeLength = status & 0x3f;
70
71 quint8 newStatus = (status & 0xd0) | locale.size();
72
73 p[0] = newStatus;
74 p.replace(1, codeLength, locale.toLatin1());
75
77}
78
83{
84 const QByteArray p = payload();
85
86 if (p.isEmpty())
87 return QString();
88
89 quint8 status = p.at(0);
90 bool utf16 = status & 0x80;
91 quint8 codeLength = status & 0x3f;
92
93 auto toUnicode = QStringDecoder(
96
97 return toUnicode(QByteArrayView(p.constData() + 1 + codeLength, p.size() - 1 - codeLength));
98}
99
104{
105 if (payload().isEmpty())
107
108 QByteArray p = payload();
109
110 quint8 status = p.at(0);
111
112 bool utf16 = status & 0x80;
113 quint8 codeLength = status & 0x3f;
114
115 p.truncate(1 + codeLength);
116
117 auto fromUnicode = QStringEncoder(
120
121 p += fromUnicode(text);
122
123 setPayload(p);
124}
125
130{
131 if (payload().isEmpty())
132 return Utf8;
133
134 QByteArray p = payload();
135
136 quint8 status = p.at(0);
137
138 bool utf16 = status & 0x80;
139
140 if (utf16)
141 return Utf16;
142 else
143 return Utf8;
144}
145
150{
151 QByteArray p = payload();
152
153 quint8 status = p.isEmpty() ? 0 : p.at(0);
154
155 QString string = text();
156
157 if (encoding == Utf8)
158 status &= ~0x80;
159 else
160 status |= 0x80;
161
162 p[0] = status;
163
164 setPayload(p);
165
166 setText(string);
167}
168
\inmodule QtCore
Definition qbytearray.h:57
void setLocale(const QString &locale)
Sets the locale of the text record to locale.
QString text() const
Returns the contents of the text record as a string.
void setEncoding(Encoding encoding)
Sets the enconding of the contents to encoding.
Encoding
This enum describes the text encoding standard used.
Encoding encoding() const
Returns the encoding of the contents.
void setText(const QString text)
Sets the contents of the text record to text.
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 isEmpty() const
Returns true if the NDEF record contains an empty payload; otherwise returns false.
\inmodule QtCore
\inmodule QtCore
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition qstring.cpp:5871
QString text
Combined button and popup list for selecting options.
GLuint name
GLfloat GLfloat p
[1]
unsigned char quint8
Definition qtypes.h:46