summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2019-06-19 17:30:28 -0700
committerThiago Macieira <thiago.macieira@intel.com>2019-11-19 13:48:29 +0100
commit329eef34f4401e2303a60b70904c7f58ccf64af8 (patch)
tree5050f7ecf00e0f1b89cb8073aa38157ce7a273bd /src
parent84056cdca11c63ddb9fac3d95fcfa952adaa6ea1 (diff)
Add functions for facilitating adding UTF-8 and US-ASCII strings
Change-Id: Ief874765cd7b43798de3fffd15a9c0b4dc82a64e Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/corelib/serialization/qcborvalue_p.h9
-rw-r--r--src/corelib/serialization/qjsonparser.cpp7
2 files changed, 13 insertions, 3 deletions
diff --git a/src/corelib/serialization/qcborvalue_p.h b/src/corelib/serialization/qcborvalue_p.h
index d18d108969..b5d3de74fe 100644
--- a/src/corelib/serialization/qcborvalue_p.h
+++ b/src/corelib/serialization/qcborvalue_p.h
@@ -236,6 +236,15 @@ public:
elements.append(QtCbor::Element(addByteData(data, len), type,
QtCbor::Element::HasByteData | extraFlags));
}
+ void appendAsciiString(const QString &s);
+ void appendAsciiString(const char *str, qsizetype len)
+ {
+ appendByteData(str, len, QCborValue::String, QtCbor::Element::StringIsAscii);
+ }
+ void appendUtf8String(const char *str, qsizetype len)
+ {
+ appendByteData(str, len, QCborValue::String);
+ }
void append(QLatin1String s)
{
if (!QtPrivate::isAscii(s))
diff --git a/src/corelib/serialization/qjsonparser.cpp b/src/corelib/serialization/qjsonparser.cpp
index aab8112d7f..d7ce702ff7 100644
--- a/src/corelib/serialization/qjsonparser.cpp
+++ b/src/corelib/serialization/qjsonparser.cpp
@@ -894,9 +894,10 @@ bool Parser::parseString()
// no escape sequences, we are done
if (isUtf8) {
- container->appendByteData(start, json - start - 1, QCborValue::String,
- isAscii ? QtCbor::Element::StringIsAscii
- : QtCbor::Element::ValueFlags {});
+ if (isAscii)
+ container->appendAsciiString(start, json - start - 1);
+ else
+ container->appendUtf8String(start, json - start - 1);
END;
return true;
}