summaryrefslogtreecommitdiffstats
path: root/src/corelib/plugin
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@nokia.com>2011-05-20 09:36:01 (GMT)
committerLiang Qi <liang.qi@nokia.com>2011-05-20 12:28:12 (GMT)
commit71f923f29e2c60444a85fc765fc582e06cb7eca4 (patch)
treed226463c2128c084ef83fcaf304912cb03934867 /src/corelib/plugin
parent7ce566ed82666ac08f137f4d8590ce589d42c82a (diff)
downloadQt-71f923f29e2c60444a85fc765fc582e06cb7eca4.zip
Qt-71f923f29e2c60444a85fc765fc582e06cb7eca4.tar.gz
Qt-71f923f29e2c60444a85fc765fc582e06cb7eca4.tar.bz2
Add QUuid::toByteArray() and relevant
Add QUuid::toByteArray() and QUuid(const QByteArray &). Same behavior with QUuid::toString() and QUuid(const QString &). Task-number: QTBUG-19419 Reviewed-by: joao
Diffstat (limited to 'src/corelib/plugin')
-rw-r--r--src/corelib/plugin/quuid.cpp79
-rw-r--r--src/corelib/plugin/quuid.h2
2 files changed, 81 insertions, 0 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index e4adf13..c80d0f5 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -344,6 +344,39 @@ QUuid::QUuid(const char *text)
{
*this = QUuid(QString::fromLatin1(text));
}
+
+/*!
+ Creates a QUuid object from the QByteArray \a text, which must be
+ formatted as five hex fields separated by '-', e.g.,
+ "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where 'x' is a hex
+ digit. The curly braces shown here are optional, but it is normal to
+ include them. If the conversion fails, a null UUID is created. See
+ toByteArray() for an explanation of how the five hex fields map to the
+ public data members in QUuid.
+
+ \since 4.8
+
+ \sa toByteArray(), QUuid()
+*/
+QUuid::QUuid(const QByteArray &text)
+{
+ if (text.length() < 36) {
+ *this = QUuid();
+ return;
+ }
+
+ const char *data = text.constData();
+
+ if (*data == '{' && text.length() < 37) {
+ *this = QUuid();
+ return;
+ }
+
+ if (!_q_uuidFromHex(data, data1, data2, data3, data4)) {
+ *this = QUuid();
+ return;
+ }
+}
#endif
/*!
@@ -411,6 +444,52 @@ QString QUuid::toString() const
return result;
}
+
+/*!
+ Returns the binary representation of this QUuid. The byte array is
+ formatted as five hex fields separated by '-' and enclosed in
+ curly braces, i.e., "{xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx}" where
+ 'x' is a hex digit. From left to right, the five hex fields are
+ obtained from the four public data members in QUuid as follows:
+
+ \table
+ \header
+ \o Field #
+ \o Source
+
+ \row
+ \o 1
+ \o data1
+
+ \row
+ \o 2
+ \o data2
+
+ \row
+ \o 3
+ \o data3
+
+ \row
+ \o 4
+ \o data4[0] .. data4[1]
+
+ \row
+ \o 5
+ \o data4[2] .. data4[7]
+
+ \endtable
+
+ \since 4.8
+*/
+QByteArray QUuid::toByteArray() const
+{
+ QByteArray result(38, Qt::Uninitialized);
+ char *data = result.data();
+
+ _q_uuidToHex(data, data1, data2, data3, data4);
+
+ return result;
+}
#endif
#ifndef QT_NO_DATASTREAM
diff --git a/src/corelib/plugin/quuid.h b/src/corelib/plugin/quuid.h
index 39f0179..ecaae48 100644
--- a/src/corelib/plugin/quuid.h
+++ b/src/corelib/plugin/quuid.h
@@ -109,6 +109,8 @@ struct Q_CORE_EXPORT QUuid
QUuid(const char *);
QString toString() const;
operator QString() const { return toString(); } // ### Qt5 remove
+ QUuid(const QByteArray &);
+ QByteArray toByteArray() const;
#endif
bool isNull() const;