10#include <private/qnumeric_p.h>
12#include <private/qtools_p.h>
19class DiagnosticNotation
24 DiagnosticNotation dn(opts);
30 QStack<int> byteArrayFormatStack;
33 QCborValue::DiagnosticNotationOptions opts;
37 enum { IndentationWidth = 4 };
38 DiagnosticNotation *dn;
39 Nest(DiagnosticNotation *that) : dn(that)
42 static const char indent[IndentationWidth + 1] =
" ";
50 dn->separator.
chop(IndentationWidth);
54 DiagnosticNotation(QCborValue::DiagnosticNotationOptions opts_)
55 : separator(opts_ &
QCborValue::LineWrapped ?
"\n"_L1 :
""_L1), opts(opts_)
75 }
else if (convertDoubleTo(
d, &
v)) {
81 if (!
s.contains(u
'.') && !
s.contains(u
'e'))
98void DiagnosticNotation::appendString(
const QString &
s)
109 if (uc ==
'\\' || uc ==
'"' || uc <
' ' || uc >= 0x7f)
120 static const char escapeMap[16] = {
131 buf[1] = QChar::Null;
132 char16_t uc =
ptr->unicode();
134 if (uc <
sizeof(escapeMap))
136 else if (uc ==
'"' || uc ==
'\\')
139 if (
buf[1] == QChar::Null) {
140 const auto toHexUpper = [](
char32_t value) ->
QChar {
144 if (
ptr->isHighSurrogate() && (
ptr + 1) !=
end &&
ptr[1].isLowSurrogate()) {
147 char32_t ucs4 = QChar::surrogateToUcs4(uc,
ptr->unicode());
151 buf[4] = toHexUpper(ucs4 >> 20);
152 buf[5] = toHexUpper(ucs4 >> 16);
153 buf[6] = toHexUpper(ucs4 >> 12);
154 buf[7] = toHexUpper(ucs4 >> 8);
155 buf[8] = toHexUpper(ucs4 >> 4);
156 buf[9] = toHexUpper(ucs4);
160 buf[2] = toHexUpper(uc >> 12);
161 buf[3] = toHexUpper(uc >> 8);
162 buf[4] = toHexUpper(uc >> 4);
163 buf[5] = toHexUpper(uc);
175void DiagnosticNotation::appendArray(
const QCborArray &
a)
185 result += comma + separator;
191 result += separator + u
']';
194void DiagnosticNotation::appendMap(
const QCborMap &
m)
204 result += comma + separator;
206 appendValue(
v.first);
208 appendValue(
v.second);
212 result += separator + u
'}';
215void DiagnosticNotation::appendValue(
const QCborValue &
v)
222 switch (byteArrayFormatStack.top()) {
239 return appendString(
v.toString());
241 return appendArray(
v.toArray());
273 byteArrayFormatStack.push(
int(
v.tag()));
275 appendValue(
v.taggedValue());
278 byteArrayFormatStack.pop();
313 return DiagnosticNotation::create(*
this, opts);
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
\inmodule QtCore\reentrant
QString toDiagnosticNotation(DiagnosticNotationOptions opts=Compact) const
Creates the diagnostic notation equivalent of this CBOR object and returns it.
\macro QT_RESTRICTED_CAST_FROM_ASCII
void chop(qsizetype n)
Removes n characters from the end of the string.
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
static QString number(int, int base=10)
This is an overloaded member function, provided for convenience. It differs from the above function o...
const char * toHex(ushort u, char *buffer)
Combined button and popup list for selecting options.
constexpr char toHexUpper(char32_t value) noexcept
void toByteArray(QByteArray &)
static QString makeFpString(double d)
static bool isByteArrayEncodingTag(QCborTag tag)
AudioChannelLayoutTag tag
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
static ControlElement< T > * ptr(QWidget *widget)
static Q_DECL_CONST_FUNCTION bool qt_is_nan(double d)
static Q_DECL_CONST_FUNCTION bool qt_is_inf(double d)
GLsizei const GLfloat * v
[13]
GLboolean GLboolean GLboolean GLboolean a
[7]
GLenum GLuint GLenum GLsizei const GLchar * buf
QtPrivate::QRegularExpressionMatchIteratorRangeBasedForIterator begin(const QRegularExpressionMatchIterator &iterator)
#define QStringLiteral(str)
unsigned long long quint64
void appendMap(QCborStreamWriter &writer, const QList< std::pair< int, QString > > &values)
[21]
\inmodule QtCore \reentrant