+#ifndef QT_NO_QUUID_STRING
+template <class Char, class Integral>
+void _q_toHex(Char *&dst, Integral value)
+{
+ static const char digits[] = "0123456789abcdef";
+
+ if (sizeof(Integral) > 1)
+ value = qToBigEndian(value);
+
+ const char* p = reinterpret_cast<const char*>(&value);
+
+ for (uint i = 0; i < sizeof(Integral); ++i, dst += 2) {
+ uint j = (p[i] >> 4) & 0xf;
+ dst[0] = Char(digits[j]);
+ j = p[i] & 0xf;
+ dst[1] = Char(digits[j]);
+ }
+}
+
+template <class Char, class Integral>
+bool _q_fromHex(const Char *&src, Integral &value)
+{
+ value = 0;
+
+ for (uint i = 0; i < sizeof(Integral) * 2; ++i) {
+ int ch = *src++;
+ int tmp;
+ if (ch >= '0' && ch <= '9')
+ tmp = ch - '0';
+ else if (ch >= 'a' && ch <= 'f')
+ tmp = ch - 'a' + 10;
+ else if (ch >= 'A' && ch <= 'F')
+ tmp = ch - 'A' + 10;
+ else
+ return false;
+
+ value = value * 16 + tmp;
+ }
+
+ return true;
+}
+
+template <class Char>
+void _q_uuidToHex(Char *&dst, const uint &d1, const ushort &d2, const ushort &d3, const uchar (&d4)[8])
+{
+ *dst++ = Char('{');
+ _q_toHex(dst, d1);
+ *dst++ = Char('-');
+ _q_toHex(dst, d2);
+ *dst++ = Char('-');
+ _q_toHex(dst, d3);
+ *dst++ = Char('-');
+ for (int i = 0; i < 2; i++)
+ _q_toHex(dst, d4[i]);
+ *dst++ = Char('-');
+ for (int i = 2; i < 8; i++)
+ _q_toHex(dst, d4[i]);
+ *dst = Char('}');
+}
+
+template <class Char>
+bool _q_uuidFromHex(const Char *&src, uint &d1, ushort &d2, ushort &d3, uchar (&d4)[8])
+{
+ if (*src == Char('{'))
+ src++;
+ if (!_q_fromHex(src, d1)
+ || *src++ != Char('-')
+ || !_q_fromHex(src, d2)
+ || *src++ != Char('-')
+ || !_q_fromHex(src, d3)
+ || *src++ != Char('-')
+ || !_q_fromHex(src, d4[0])
+ || !_q_fromHex(src, d4[1])
+ || *src++ != Char('-')
+ || !_q_fromHex(src, d4[2])
+ || !_q_fromHex(src, d4[3])
+ || !_q_fromHex(src, d4[4])
+ || !_q_fromHex(src, d4[5])
+ || !_q_fromHex(src, d4[6])
+ || !_q_fromHex(src, d4[7])) {
+ return false;
+ }
+
+ return true;
+}
+#endif
+