diff options
Diffstat (limited to 'src/corelib/plugin/quuid.cpp')
| -rw-r--r-- | src/corelib/plugin/quuid.cpp | 119 |
1 files changed, 112 insertions, 7 deletions
diff --git a/src/corelib/plugin/quuid.cpp b/src/corelib/plugin/quuid.cpp index 3a1c0495fe0..4d658e064c5 100644 --- a/src/corelib/plugin/quuid.cpp +++ b/src/corelib/plugin/quuid.cpp @@ -83,21 +83,27 @@ bool _q_fromHex(const char *&src, Integral &value) return true; } -static char *_q_uuidToHex(const QUuid &uuid, char *dst) +static char *_q_uuidToHex(const QUuid &uuid, char *dst, QUuid::StringFormat mode = QUuid::WithBraces) { - *dst++ = '{'; + if ((mode & QUuid::WithoutBraces) == 0) + *dst++ = '{'; _q_toHex(dst, uuid.data1); - *dst++ = '-'; + if ((mode & QUuid::Id128) != QUuid::Id128) + *dst++ = '-'; _q_toHex(dst, uuid.data2); - *dst++ = '-'; + if ((mode & QUuid::Id128) != QUuid::Id128) + *dst++ = '-'; _q_toHex(dst, uuid.data3); - *dst++ = '-'; + if ((mode & QUuid::Id128) != QUuid::Id128) + *dst++ = '-'; for (int i = 0; i < 2; i++) _q_toHex(dst, uuid.data4[i]); - *dst++ = '-'; + if ((mode & QUuid::Id128) != QUuid::Id128) + *dst++ = '-'; for (int i = 2; i < 8; i++) _q_toHex(dst, uuid.data4[i]); - *dst++ = '}'; + if ((mode & QUuid::WithoutBraces) == 0) + *dst++ = '}'; return dst; } @@ -307,6 +313,22 @@ static QUuid createFromName(const QUuid &ns, const QByteArray &baseData, QCrypto */ /*! + \enum QUuid::StringFormat + \since 5.11 + + This enum is used by toString(StringFormat) to control the formatting of the + string representation. The possible values are: + + \value WithBraces The default, toString() will return five hex fields, separated by + dashes and surrounded by braces. Example: + {00000000-0000-0000-0000-000000000000}. + \value WithoutBraces Only the five dash-separated fields, without the braces. Example: + 00000000-0000-0000-0000-000000000000. + \value Id128 Only the hex digits, without braces or dashes. Note that QUuid + cannot parse this back again as input. +*/ + +/*! \fn QUuid::QUuid(const GUID &guid) Casts a Windows \a guid to a Qt QUuid. @@ -592,6 +614,47 @@ QString QUuid::toString() const } /*! + \since 5.11 + + Returns the string representation of this QUuid, with the formattiong + controlled by the \a mode parameter. From left to right, the five hex + fields are obtained from the four public data members in QUuid as follows: + + \table + \header + \li Field # + \li Source + + \row + \li 1 + \li data1 + + \row + \li 2 + \li data2 + + \row + \li 3 + \li data3 + + \row + \li 4 + \li data4[0] .. data4[1] + + \row + \li 5 + \li data4[2] .. data4[7] + + \endtable +*/ +QString QUuid::toString(QUuid::StringFormat mode) const +{ + char latin1[MaxStringUuidLength]; + const auto end = _q_uuidToHex(*this, latin1, mode); + return QString::fromLatin1(latin1, end - latin1); +} + +/*! 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 @@ -637,6 +700,48 @@ QByteArray QUuid::toByteArray() const } /*! + \since 5.11 + + Returns the string representation of this QUuid, with the formattiong + controlled by the \a mode parameter. From left to right, the five hex + fields are obtained from the four public data members in QUuid as follows: + + \table + \header + \li Field # + \li Source + + \row + \li 1 + \li data1 + + \row + \li 2 + \li data2 + + \row + \li 3 + \li data3 + + \row + \li 4 + \li data4[0] .. data4[1] + + \row + \li 5 + \li data4[2] .. data4[7] + + \endtable +*/ +QByteArray QUuid::toByteArray(QUuid::StringFormat mode) const +{ + QByteArray result(MaxStringUuidLength, Qt::Uninitialized); + const auto end = _q_uuidToHex(*this, const_cast<char*>(result.constData()), mode); + result.resize(end - result.constData()); + return result; +} + +/*! Returns the binary representation of this QUuid. The byte array is in big endian format, and formatted according to RFC 4122, section 4.1.2 - "Layout and byte order". |
