diff options
author | Liang Qi <liang.qi@nokia.com> | 2011-05-20 09:36:01 (GMT) |
---|---|---|
committer | Liang Qi <liang.qi@nokia.com> | 2011-05-20 12:28:12 (GMT) |
commit | 71f923f29e2c60444a85fc765fc582e06cb7eca4 (patch) | |
tree | d226463c2128c084ef83fcaf304912cb03934867 /src/corelib/plugin/quuid.cpp | |
parent | 7ce566ed82666ac08f137f4d8590ce589d42c82a (diff) | |
download | Qt-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/quuid.cpp')
-rw-r--r-- | src/corelib/plugin/quuid.cpp | 79 |
1 files changed, 79 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 |