summaryrefslogtreecommitdiff
path: root/src/corelib/plugin/quuid.cpp
diff options
context:
space:
mode:
authorLiang Qi <liang.qi@nokia.com>2011-05-20 11:36:01 +0200
committerQt Continuous Integration System <qt-info@nokia.com>2011-05-27 13:21:42 +0200
commit8f4c007f85a4c16728281cb36f2f0f85b56c0999 (patch)
treef8bf7122d92a9b6f93a8fc7057beadb0f44d053a /src/corelib/plugin/quuid.cpp
parentc8888b518bd733778518e1643682f97bc7b28b64 (diff)
downloadqtbase-8f4c007f85a4c16728281cb36f2f0f85b56c0999.tar.gz
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 (cherry picked from commit 71f923f29e2c60444a85fc765fc582e06cb7eca4) Change-Id: I41dad65e269f739ba9ec1c27e9da96af6401356c Reviewed-on: http://codereview.qt.nokia.com/167 Reviewed-by: Liang Qi <liang.qi@nokia.com>
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
-rw-r--r--src/corelib/plugin/quuid.cpp79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp
index 796ee01602..facd732609 100644
--- a/src/corelib/plugin/quuid.cpp
+++ b/src/corelib/plugin/quuid.cpp
@@ -351,6 +351,39 @@ QUuid::QUuid(const char *text)
return;
}
}
+
+/*!
+ 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
/*!
@@ -418,6 +451,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