VirtualBox

Changeset 19198 in vbox for trunk


Ignore:
Timestamp:
Apr 27, 2009 9:25:37 AM (16 years ago)
Author:
vboxsync
Message:

IPRT: Added RTUuidFrom/ToUtf16. (untested)

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/include/iprt/uuid.h

    r11413 r19198  
    140140RTDECL(int)  RTUuidFromStr(PRTUUID pUuid, const char *pszString);
    141141
     142/**
     143 * Converts binary UUID to its UTF-16 string representation.
     144 *
     145 * @note See note in RTUuidToStr.
     146 *
     147 * @sa RTUUID::Gen
     148 *
     149 * @returns iprt status code.
     150 * @param   pUuid           Uuid to convert.
     151 * @param   pwszString      Where to store result string.
     152 * @param   cwcString       pszString buffer length, must be >=
     153 *                          RTUUID_STR_LENGTH.
     154 */
     155RTDECL(int)  RTUuidToUtf16(PCRTUUID pUuid, PRTUTF16 pwszString, size_t cwcString);
     156
     157/**
     158 * Converts UUID from its UTF-16 string representation to binary format.
     159 *
     160 * @note See note in RTUuidFromStr.
     161 *
     162 * @sa RTUUID::Gen
     163 *
     164 * @returns iprt status code.
     165 * @param   pUuid           Where to store result Uuid.
     166 * @param   pwszString      String with UUID text data.
     167 */
     168RTDECL(int)  RTUuidFromUtf16(PRTUUID pUuid, PCRTUTF16 pwszString);
     169
    142170/** @} */
    143171
  • trunk/src/VBox/Runtime/generic/uuid-generic.cpp

    r14067 r19198  
    3838
    3939
     40/*******************************************************************************
     41*   Global Variables                                                           *
     42*******************************************************************************/
     43/** Conversion table used by the conversion functions.
     44 * 0xff if not a hex number, otherwise the value. */
     45static const uint8_t g_au8Digits[256] =
     46{
     47    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 0..0f */
     48    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 10..1f */
     49    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 20..2f */
     50    0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07,  0x08,0x09,0xff,0xff, 0xff,0xff,0xff,0xff, /* 30..3f */
     51    0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 40..4f */
     52    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 50..5f */
     53    0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 60..6f */
     54    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 70..7f */
     55    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 80..8f */
     56    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 90..9f */
     57    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* a0..af */
     58    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* b0..bf */
     59    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* c0..cf */
     60    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* d0..df */
     61    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* e0..ef */
     62    0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* f0..ff */
     63};
     64/** Conversion to string. */
     65static const char g_achDigits[17] = "0123456789abcdef";
     66
     67
     68
    4069/* WARNING: This implementation ASSUMES little endian. Does not work on big endian! */
    4170
     
    124153RTDECL(int)  RTUuidToStr(PCRTUUID pUuid, char *pszString, size_t cchString)
    125154{
    126     static const char s_achDigits[17] = "0123456789abcdef";
    127155    uint32_t u32TimeLow;
    128156    unsigned u;
     
    148176     */
    149177    u32TimeLow = pUuid->Gen.u32TimeLow;
    150     pszString[ 0] = s_achDigits[(u32TimeLow >> 28)/*& 0xf*/];
    151     pszString[ 1] = s_achDigits[(u32TimeLow >> 24) & 0xf];
    152     pszString[ 2] = s_achDigits[(u32TimeLow >> 20) & 0xf];
    153     pszString[ 3] = s_achDigits[(u32TimeLow >> 16) & 0xf];
    154     pszString[ 4] = s_achDigits[(u32TimeLow >> 12) & 0xf];
    155     pszString[ 5] = s_achDigits[(u32TimeLow >>  8) & 0xf];
    156     pszString[ 6] = s_achDigits[(u32TimeLow >>  4) & 0xf];
    157     pszString[ 7] = s_achDigits[(u32TimeLow/*>>0*/)& 0xf];
     178    pszString[ 0] = g_achDigits[(u32TimeLow >> 28)/*& 0xf*/];
     179    pszString[ 1] = g_achDigits[(u32TimeLow >> 24) & 0xf];
     180    pszString[ 2] = g_achDigits[(u32TimeLow >> 20) & 0xf];
     181    pszString[ 3] = g_achDigits[(u32TimeLow >> 16) & 0xf];
     182    pszString[ 4] = g_achDigits[(u32TimeLow >> 12) & 0xf];
     183    pszString[ 5] = g_achDigits[(u32TimeLow >>  8) & 0xf];
     184    pszString[ 6] = g_achDigits[(u32TimeLow >>  4) & 0xf];
     185    pszString[ 7] = g_achDigits[(u32TimeLow/*>>0*/)& 0xf];
    158186    pszString[ 8] = '-';
    159187    u = pUuid->Gen.u16TimeMid;
    160     pszString[ 9] = s_achDigits[(u >> 12)/*& 0xf*/];
    161     pszString[10] = s_achDigits[(u >>  8) & 0xf];
    162     pszString[11] = s_achDigits[(u >>  4) & 0xf];
    163     pszString[12] = s_achDigits[(u/*>>0*/)& 0xf];
     188    pszString[ 9] = g_achDigits[(u >> 12)/*& 0xf*/];
     189    pszString[10] = g_achDigits[(u >>  8) & 0xf];
     190    pszString[11] = g_achDigits[(u >>  4) & 0xf];
     191    pszString[12] = g_achDigits[(u/*>>0*/)& 0xf];
    164192    pszString[13] = '-';
    165193    u = pUuid->Gen.u16TimeHiAndVersion;
    166     pszString[14] = s_achDigits[(u >> 12)/*& 0xf*/];
    167     pszString[15] = s_achDigits[(u >>  8) & 0xf];
    168     pszString[16] = s_achDigits[(u >>  4) & 0xf];
    169     pszString[17] = s_achDigits[(u/*>>0*/)& 0xf];
     194    pszString[14] = g_achDigits[(u >> 12)/*& 0xf*/];
     195    pszString[15] = g_achDigits[(u >>  8) & 0xf];
     196    pszString[16] = g_achDigits[(u >>  4) & 0xf];
     197    pszString[17] = g_achDigits[(u/*>>0*/)& 0xf];
    170198    pszString[18] = '-';
    171     pszString[19] = s_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved >> 4];
    172     pszString[20] = s_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved & 0xf];
    173     pszString[21] = s_achDigits[pUuid->Gen.u8ClockSeqLow >> 4];
    174     pszString[22] = s_achDigits[pUuid->Gen.u8ClockSeqLow & 0xf];
     199    pszString[19] = g_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved >> 4];
     200    pszString[20] = g_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved & 0xf];
     201    pszString[21] = g_achDigits[pUuid->Gen.u8ClockSeqLow >> 4];
     202    pszString[22] = g_achDigits[pUuid->Gen.u8ClockSeqLow & 0xf];
    175203    pszString[23] = '-';
    176     pszString[24] = s_achDigits[pUuid->Gen.au8Node[0] >> 4];
    177     pszString[25] = s_achDigits[pUuid->Gen.au8Node[0] & 0xf];
    178     pszString[26] = s_achDigits[pUuid->Gen.au8Node[1] >> 4];
    179     pszString[27] = s_achDigits[pUuid->Gen.au8Node[1] & 0xf];
    180     pszString[28] = s_achDigits[pUuid->Gen.au8Node[2] >> 4];
    181     pszString[29] = s_achDigits[pUuid->Gen.au8Node[2] & 0xf];
    182     pszString[30] = s_achDigits[pUuid->Gen.au8Node[3] >> 4];
    183     pszString[31] = s_achDigits[pUuid->Gen.au8Node[3] & 0xf];
    184     pszString[32] = s_achDigits[pUuid->Gen.au8Node[4] >> 4];
    185     pszString[33] = s_achDigits[pUuid->Gen.au8Node[4] & 0xf];
    186     pszString[34] = s_achDigits[pUuid->Gen.au8Node[5] >> 4];
    187     pszString[35] = s_achDigits[pUuid->Gen.au8Node[5] & 0xf];
     204    pszString[24] = g_achDigits[pUuid->Gen.au8Node[0] >> 4];
     205    pszString[25] = g_achDigits[pUuid->Gen.au8Node[0] & 0xf];
     206    pszString[26] = g_achDigits[pUuid->Gen.au8Node[1] >> 4];
     207    pszString[27] = g_achDigits[pUuid->Gen.au8Node[1] & 0xf];
     208    pszString[28] = g_achDigits[pUuid->Gen.au8Node[2] >> 4];
     209    pszString[29] = g_achDigits[pUuid->Gen.au8Node[2] & 0xf];
     210    pszString[30] = g_achDigits[pUuid->Gen.au8Node[3] >> 4];
     211    pszString[31] = g_achDigits[pUuid->Gen.au8Node[3] & 0xf];
     212    pszString[32] = g_achDigits[pUuid->Gen.au8Node[4] >> 4];
     213    pszString[33] = g_achDigits[pUuid->Gen.au8Node[4] & 0xf];
     214    pszString[34] = g_achDigits[pUuid->Gen.au8Node[5] >> 4];
     215    pszString[35] = g_achDigits[pUuid->Gen.au8Node[5] & 0xf];
    188216    pszString[36] = '\0';
    189217
     
    194222RTDECL(int)  RTUuidFromStr(PRTUUID pUuid, const char *pszString)
    195223{
    196     /* 0xff if not a hex number, otherwise the value. (Assumes UTF-8 encoded strings.) */
    197     static const uint8_t s_aDigits[256] =
    198     {
    199         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 0..0f */
    200         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 10..1f */
    201         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 20..2f */
    202         0x00,0x01,0x02,0x03, 0x04,0x05,0x06,0x07,  0x08,0x09,0xff,0xff, 0xff,0xff,0xff,0xff, /* 30..3f */
    203         0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 40..4f */
    204         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 50..5f */
    205         0xff,0x0a,0x0b,0x0c, 0x0d,0x0e,0x0f,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 60..6f */
    206         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 70..7f */
    207         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 80..8f */
    208         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* 90..9f */
    209         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* a0..af */
    210         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* b0..bf */
    211         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* c0..cf */
    212         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* d0..df */
    213         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* e0..ef */
    214         0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff,  0xff,0xff,0xff,0xff, 0xff,0xff,0xff,0xff, /* f0..ff */
    215     };
    216 
    217224    /*
    218225     * Validate parameters.
     
    222229
    223230#define MY_CHECK(expr) do { if (RT_UNLIKELY(!(expr))) return VERR_INVALID_UUID_FORMAT; } while (0)
    224 #define MY_ISXDIGIT(ch) (s_aDigits[(ch) & 0xff] != 0xff)
     231#define MY_ISXDIGIT(ch) (g_au8Digits[(ch) & 0xff] != 0xff)
    225232    MY_CHECK(MY_ISXDIGIT(pszString[ 0]));
    226233    MY_CHECK(MY_ISXDIGIT(pszString[ 1]));
     
    266273     * Inverse of RTUuidToStr (see above).
    267274     */
    268 #define MY_TONUM(ch) (s_aDigits[(ch) & 0xff])
     275#define MY_TONUM(ch) (g_au8Digits[(ch) & 0xff])
    269276    pUuid->Gen.u32TimeLow = (uint32_t)MY_TONUM(pszString[ 0]) << 28
    270277                          | (uint32_t)MY_TONUM(pszString[ 1]) << 24
     
    306313}
    307314
     315
     316RTDECL(int)  RTUuidToUtf16(PCRTUUID pUuid, PRTUTF16 pwszString, size_t cwcString)
     317{
     318    static const char g_achDigits[17] = "0123456789abcdef";
     319    uint32_t u32TimeLow;
     320    unsigned u;
     321
     322    /* validate parameters */
     323    AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
     324    AssertPtrReturn(pwszString, VERR_INVALID_PARAMETER);
     325    AssertReturn(cwcString >= RTUUID_STR_LENGTH, VERR_INVALID_PARAMETER);
     326
     327    /*
     328     * RTStrPrintf(,,"%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x",
     329     *             pUuid->Gen.u32TimeLow,
     330     *             pUuid->Gen.u16TimeMin,
     331     *             pUuid->Gen.u16TimeHiAndVersion,
     332     *             pUuid->Gen.u16ClockSeq & 0xff,
     333     *             pUuid->Gen.u16ClockSeq >> 8,
     334     *             pUuid->Gen.au8Node[0],
     335     *             pUuid->Gen.au8Node[1],
     336     *             pUuid->Gen.au8Node[2],
     337     *             pUuid->Gen.au8Node[3],
     338     *             pUuid->Gen.au8Node[4],
     339     *             pUuid->Gen.au8Node[5]);
     340     */
     341    u32TimeLow = pUuid->Gen.u32TimeLow;
     342    pwszString[ 0] = g_achDigits[(u32TimeLow >> 28)/*& 0xf*/];
     343    pwszString[ 1] = g_achDigits[(u32TimeLow >> 24) & 0xf];
     344    pwszString[ 2] = g_achDigits[(u32TimeLow >> 20) & 0xf];
     345    pwszString[ 3] = g_achDigits[(u32TimeLow >> 16) & 0xf];
     346    pwszString[ 4] = g_achDigits[(u32TimeLow >> 12) & 0xf];
     347    pwszString[ 5] = g_achDigits[(u32TimeLow >>  8) & 0xf];
     348    pwszString[ 6] = g_achDigits[(u32TimeLow >>  4) & 0xf];
     349    pwszString[ 7] = g_achDigits[(u32TimeLow/*>>0*/)& 0xf];
     350    pwszString[ 8] = '-';
     351    u = pUuid->Gen.u16TimeMid;
     352    pwszString[ 9] = g_achDigits[(u >> 12)/*& 0xf*/];
     353    pwszString[10] = g_achDigits[(u >>  8) & 0xf];
     354    pwszString[11] = g_achDigits[(u >>  4) & 0xf];
     355    pwszString[12] = g_achDigits[(u/*>>0*/)& 0xf];
     356    pwszString[13] = '-';
     357    u = pUuid->Gen.u16TimeHiAndVersion;
     358    pwszString[14] = g_achDigits[(u >> 12)/*& 0xf*/];
     359    pwszString[15] = g_achDigits[(u >>  8) & 0xf];
     360    pwszString[16] = g_achDigits[(u >>  4) & 0xf];
     361    pwszString[17] = g_achDigits[(u/*>>0*/)& 0xf];
     362    pwszString[18] = '-';
     363    pwszString[19] = g_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved >> 4];
     364    pwszString[20] = g_achDigits[pUuid->Gen.u8ClockSeqHiAndReserved & 0xf];
     365    pwszString[21] = g_achDigits[pUuid->Gen.u8ClockSeqLow >> 4];
     366    pwszString[22] = g_achDigits[pUuid->Gen.u8ClockSeqLow & 0xf];
     367    pwszString[23] = '-';
     368    pwszString[24] = g_achDigits[pUuid->Gen.au8Node[0] >> 4];
     369    pwszString[25] = g_achDigits[pUuid->Gen.au8Node[0] & 0xf];
     370    pwszString[26] = g_achDigits[pUuid->Gen.au8Node[1] >> 4];
     371    pwszString[27] = g_achDigits[pUuid->Gen.au8Node[1] & 0xf];
     372    pwszString[28] = g_achDigits[pUuid->Gen.au8Node[2] >> 4];
     373    pwszString[29] = g_achDigits[pUuid->Gen.au8Node[2] & 0xf];
     374    pwszString[30] = g_achDigits[pUuid->Gen.au8Node[3] >> 4];
     375    pwszString[31] = g_achDigits[pUuid->Gen.au8Node[3] & 0xf];
     376    pwszString[32] = g_achDigits[pUuid->Gen.au8Node[4] >> 4];
     377    pwszString[33] = g_achDigits[pUuid->Gen.au8Node[4] & 0xf];
     378    pwszString[34] = g_achDigits[pUuid->Gen.au8Node[5] >> 4];
     379    pwszString[35] = g_achDigits[pUuid->Gen.au8Node[5] & 0xf];
     380    pwszString[36] = '\0';
     381
     382    return VINF_SUCCESS;
     383}
     384
     385
     386RTDECL(int)  RTUuidFromUtf16(PRTUUID pUuid, PCRTUTF16 pwszString)
     387{
     388
     389    /*
     390     * Validate parameters.
     391     */
     392    AssertPtrReturn(pUuid, VERR_INVALID_PARAMETER);
     393    AssertPtrReturn(pwszString, VERR_INVALID_PARAMETER);
     394
     395#define MY_CHECK(expr) do { if (RT_UNLIKELY(!(expr))) return VERR_INVALID_UUID_FORMAT; } while (0)
     396#define MY_ISXDIGIT(ch) (!((ch) & 0xff00) && g_au8Digits[(ch) & 0xff] != 0xff)
     397    MY_CHECK(MY_ISXDIGIT(pwszString[ 0]));
     398    MY_CHECK(MY_ISXDIGIT(pwszString[ 1]));
     399    MY_CHECK(MY_ISXDIGIT(pwszString[ 2]));
     400    MY_CHECK(MY_ISXDIGIT(pwszString[ 3]));
     401    MY_CHECK(MY_ISXDIGIT(pwszString[ 4]));
     402    MY_CHECK(MY_ISXDIGIT(pwszString[ 5]));
     403    MY_CHECK(MY_ISXDIGIT(pwszString[ 6]));
     404    MY_CHECK(MY_ISXDIGIT(pwszString[ 7]));
     405    MY_CHECK(pwszString[ 8] == '-');
     406    MY_CHECK(MY_ISXDIGIT(pwszString[ 9]));
     407    MY_CHECK(MY_ISXDIGIT(pwszString[10]));
     408    MY_CHECK(MY_ISXDIGIT(pwszString[11]));
     409    MY_CHECK(MY_ISXDIGIT(pwszString[12]));
     410    MY_CHECK(pwszString[13] == '-');
     411    MY_CHECK(MY_ISXDIGIT(pwszString[14]));
     412    MY_CHECK(MY_ISXDIGIT(pwszString[15]));
     413    MY_CHECK(MY_ISXDIGIT(pwszString[16]));
     414    MY_CHECK(MY_ISXDIGIT(pwszString[17]));
     415    MY_CHECK(pwszString[18] == '-');
     416    MY_CHECK(MY_ISXDIGIT(pwszString[19]));
     417    MY_CHECK(MY_ISXDIGIT(pwszString[20]));
     418    MY_CHECK(MY_ISXDIGIT(pwszString[21]));
     419    MY_CHECK(MY_ISXDIGIT(pwszString[22]));
     420    MY_CHECK(pwszString[23] == '-');
     421    MY_CHECK(MY_ISXDIGIT(pwszString[24]));
     422    MY_CHECK(MY_ISXDIGIT(pwszString[25]));
     423    MY_CHECK(MY_ISXDIGIT(pwszString[26]));
     424    MY_CHECK(MY_ISXDIGIT(pwszString[27]));
     425    MY_CHECK(MY_ISXDIGIT(pwszString[28]));
     426    MY_CHECK(MY_ISXDIGIT(pwszString[29]));
     427    MY_CHECK(MY_ISXDIGIT(pwszString[30]));
     428    MY_CHECK(MY_ISXDIGIT(pwszString[31]));
     429    MY_CHECK(MY_ISXDIGIT(pwszString[32]));
     430    MY_CHECK(MY_ISXDIGIT(pwszString[33]));
     431    MY_CHECK(MY_ISXDIGIT(pwszString[34]));
     432    MY_CHECK(MY_ISXDIGIT(pwszString[35]));
     433    MY_CHECK(!pwszString[36]);
     434#undef MY_ISXDIGIT
     435#undef MY_CHECK
     436
     437    /*
     438     * Inverse of RTUuidToUtf8 (see above).
     439     */
     440#define MY_TONUM(ch) (g_au8Digits[(ch) & 0xff])
     441    pUuid->Gen.u32TimeLow = (uint32_t)MY_TONUM(pwszString[ 0]) << 28
     442                          | (uint32_t)MY_TONUM(pwszString[ 1]) << 24
     443                          | (uint32_t)MY_TONUM(pwszString[ 2]) << 20
     444                          | (uint32_t)MY_TONUM(pwszString[ 3]) << 16
     445                          | (uint32_t)MY_TONUM(pwszString[ 4]) << 12
     446                          | (uint32_t)MY_TONUM(pwszString[ 5]) <<  8
     447                          | (uint32_t)MY_TONUM(pwszString[ 6]) <<  4
     448                          | (uint32_t)MY_TONUM(pwszString[ 7]);
     449    pUuid->Gen.u16TimeMid = (uint16_t)MY_TONUM(pwszString[ 9]) << 12
     450                          | (uint16_t)MY_TONUM(pwszString[10]) << 8
     451                          | (uint16_t)MY_TONUM(pwszString[11]) << 4
     452                          | (uint16_t)MY_TONUM(pwszString[12]);
     453    pUuid->Gen.u16TimeHiAndVersion =
     454                            (uint16_t)MY_TONUM(pwszString[14]) << 12
     455                          | (uint16_t)MY_TONUM(pwszString[15]) << 8
     456                          | (uint16_t)MY_TONUM(pwszString[16]) << 4
     457                          | (uint16_t)MY_TONUM(pwszString[17]);
     458    pUuid->Gen.u8ClockSeqHiAndReserved =
     459                            (uint16_t)MY_TONUM(pwszString[19]) << 4
     460                          | (uint16_t)MY_TONUM(pwszString[20]);
     461    pUuid->Gen.u8ClockSeqLow =
     462                            (uint16_t)MY_TONUM(pwszString[21]) << 4
     463                          | (uint16_t)MY_TONUM(pwszString[22]);
     464    pUuid->Gen.au8Node[0] = (uint8_t)MY_TONUM(pwszString[24]) << 4
     465                          | (uint8_t)MY_TONUM(pwszString[25]);
     466    pUuid->Gen.au8Node[1] = (uint8_t)MY_TONUM(pwszString[26]) << 4
     467                          | (uint8_t)MY_TONUM(pwszString[27]);
     468    pUuid->Gen.au8Node[2] = (uint8_t)MY_TONUM(pwszString[28]) << 4
     469                          | (uint8_t)MY_TONUM(pwszString[29]);
     470    pUuid->Gen.au8Node[3] = (uint8_t)MY_TONUM(pwszString[30]) << 4
     471                          | (uint8_t)MY_TONUM(pwszString[31]);
     472    pUuid->Gen.au8Node[4] = (uint8_t)MY_TONUM(pwszString[32]) << 4
     473                          | (uint8_t)MY_TONUM(pwszString[33]);
     474    pUuid->Gen.au8Node[5] = (uint8_t)MY_TONUM(pwszString[34]) << 4
     475                          | (uint8_t)MY_TONUM(pwszString[35]);
     476#undef MY_TONUM
     477    return VINF_SUCCESS;
     478}
     479
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette