27 constexpr size_t uuid_str_max = 39;
35 inline void uuidtostr(_Out_writes_z_(uuid_str_max)
char str[uuid_str_max], _In_
const uuid_t&
id)
39 _snprintf_s_l(str, uuid_str_max, _TRUNCATE,
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", NULL,
41 static_cast<unsigned int>(
id.Data2),
42 static_cast<unsigned int>(
id.Data3),
43 static_cast<unsigned int>(
id.Data4[0]),
static_cast<unsigned int>(
id.Data4[1]),
44 static_cast<unsigned int>(
id.Data4[2]),
static_cast<unsigned int>(
id.Data4[3]),
static_cast<unsigned int>(
id.Data4[4]),
static_cast<unsigned int>(
id.Data4[5]),
static_cast<unsigned int>(
id.Data4[6]),
static_cast<unsigned int>(
id.Data4[7]));
46 snprintf(str, uuid_str_max,
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
47 *
reinterpret_cast<const uint32_t*
>(&
id[0]),
48 static_cast<unsigned int>(*
reinterpret_cast<const uint16_t*
>(&
id[4])),
49 static_cast<unsigned int>(*
reinterpret_cast<const uint16_t*
>(&
id[6])),
50 static_cast<unsigned int>(
id[8]),
static_cast<unsigned int>(
id[9]),
51 static_cast<unsigned int>(
id[10]),
static_cast<unsigned int>(
id[11]),
static_cast<unsigned int>(
id[12]),
static_cast<unsigned int>(
id[13]),
static_cast<unsigned int>(
id[14]),
static_cast<unsigned int>(
id[15]));
61 inline void uuidtostr(_Out_writes_z_(uuid_str_max)
wchar_t str[uuid_str_max], _In_
const uuid_t&
id)
65 _snwprintf_s_l(str, uuid_str_max, _TRUNCATE, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", NULL,
67 static_cast<unsigned int>(
id.Data2),
68 static_cast<unsigned int>(
id.Data3),
69 static_cast<unsigned int>(
id.Data4[0]),
static_cast<unsigned int>(
id.Data4[1]),
70 static_cast<unsigned int>(
id.Data4[2]),
static_cast<unsigned int>(
id.Data4[3]),
static_cast<unsigned int>(
id.Data4[4]),
static_cast<unsigned int>(
id.Data4[5]),
static_cast<unsigned int>(
id.Data4[6]),
static_cast<unsigned int>(
id.Data4[7]));
72 swprintf(str, uuid_str_max, L
"{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}", NULL,
73 *
reinterpret_cast<const uint32_t*
>(&
id[0]),
74 static_cast<unsigned int>(*
reinterpret_cast<const uint16_t*
>(&
id[4])),
75 static_cast<unsigned int>(*
reinterpret_cast<const uint16_t*
>(&
id[6])),
76 static_cast<unsigned int>(
id[8]),
static_cast<unsigned int>(
id[9]),
77 static_cast<unsigned int>(
id[10]),
static_cast<unsigned int>(
id[11]),
static_cast<unsigned int>(
id[12]),
static_cast<unsigned int>(
id[13]),
static_cast<unsigned int>(
id[14]),
static_cast<unsigned int>(
id[15]));
90 template <
class T>
inline _Success_(
return != 0) bool strtouuid(
91 _In_reads_or_z_opt_(count) const T* str,
98 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
99 if (i >= count || str[i] !=
'{')
return false;
101 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
102 n = stdex::strtou64(&str[i], count - i, &j, 16);
103 if (n > UINT32_MAX)
return false;
105 id.Data1 =
static_cast<unsigned long>(n);
107 *
reinterpret_cast<uint32_t*
>(&
id[0]) =
static_cast<uint32_t
>(n);
110 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
111 if (i >= count || str[i] !=
'-')
return false;
113 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
114 n = stdex::strtou64(&str[i], count - i, &j, 16);
115 if (n > UINT16_MAX)
return false;
117 id.Data2 =
static_cast<unsigned short>(n);
119 *
reinterpret_cast<uint16_t*
>(&
id[4]) =
static_cast<uint16_t
>(n);
122 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
123 if (i >= count || str[i] !=
'-')
return false;
125 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
126 n = stdex::strtou64(&str[i], count - i, &j, 16);
127 if (n > UINT16_MAX)
return false;
129 id.Data3 =
static_cast<unsigned short>(n);
131 *
reinterpret_cast<uint16_t*
>(&
id[6]) =
static_cast<uint16_t
>(n);
134 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
135 if (i >= count || str[i] !=
'-')
return false;
137 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
138 n = stdex::strtou64(&str[i], count - i, &j, 16);
139 if (n > UINT16_MAX)
return false;
141 id.Data4[0] =
static_cast<unsigned char>((n >> 8) & 0xff);
142 id.Data4[1] =
static_cast<unsigned char>((n) & 0xff);
144 id[8] =
static_cast<unsigned char>((n >> 8) & 0xff);
145 id[9] =
static_cast<unsigned char>((n) & 0xff);
148 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
149 if (i >= count && str[i] !=
'-')
return false;
151 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
152 n = stdex::strtou64(&str[i], count - i, &j, 16);
153 if (n > 0xffffffffffff)
return false;
155 id.Data4[2] =
static_cast<unsigned char>((n >> 40) & 0xff);
156 id.Data4[3] =
static_cast<unsigned char>((n >> 32) & 0xff);
157 id.Data4[4] =
static_cast<unsigned char>((n >> 24) & 0xff);
158 id.Data4[5] =
static_cast<unsigned char>((n >> 16) & 0xff);
159 id.Data4[6] =
static_cast<unsigned char>((n >> 8) & 0xff);
160 id.Data4[7] =
static_cast<unsigned char>((n) & 0xff);
162 id[10] =
static_cast<unsigned char>((n >> 40) & 0xff);
163 id[11] =
static_cast<unsigned char>((n >> 32) & 0xff);
164 id[12] =
static_cast<unsigned char>((n >> 24) & 0xff);
165 id[13] =
static_cast<unsigned char>((n >> 16) & 0xff);
166 id[14] =
static_cast<unsigned char>((n >> 8) & 0xff);
167 id[15] =
static_cast<unsigned char>((n) & 0xff);
170 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
171 if (i >= count || str[i] !=
'}')
return false;
173 for (; i < count && str[i] && stdex::isspace(str[i]); ++i);
174 return i >= count || !str[i];