in src/uuid_string.c [94:144]
UUID_FROM_STRING_RESULT uuid_from_string(const char* uuid_string, UUID_T uuid) /*uuid_string is not necessarily null terminated*/
{
UUID_FROM_STRING_RESULT result;
if (
/*Codes_SRS_UUID_STRING_02_001: [ If uuid_string is NULL then uuid_from_string shall fail and return UUID_FROM_STRING_RESULT_INVALID_ARG. ]*/
(uuid_string == NULL) ||
/*Codes_SRS_UUID_STRING_02_002: [ If uuid is NULL then uuid_from_string shall fail and return UUID_FROM_STRING_RESULT_INVALID_ARG. ]*/
(uuid == NULL)
)
{
LogError("Invalid argument (uuid_string=%s, uuid=%p)", MU_P_OR_NULL(uuid_string), uuid);
result = UUID_FROM_STRING_RESULT_INVALID_ARG;
}
else
{
/*scan until either all characters are converted and deposited into the UUID_T or found a non-expected character (that includes '\0')*/
/*the below test shows where offsets are in a UUID representation as string*/
/* 1 2 3 */
/* 012345678901234567890123456789012345 */
/* 8C9F1E63-3F22-4AFD-BC7D-8D1B20F968D6 */
/*Codes_SRS_UUID_STRING_02_003: [ If any character of uuid_string doesn't match the string representation hhhhhh-hhhh-hhhh-hhhh-hhhhhhhhhh then uuid_from_string shall succeed and return UUID_FROM_STRING_RESULT_INVALID_DATA. ]*/
/*Codes_SRS_UUID_STRING_02_004: [ If any character of uuid_string is \0 instead of a hex digit then uuid_from_string shall succeed and return UUID_FROM_STRING_RESULT_INVALID_DATA. ]*/
/*Codes_SRS_UUID_STRING_02_005: [ If any character of uuid_string is \0 instead of a - then uuid_from_string shall succeed and return UUID_FROM_STRING_RESULT_INVALID_DATA. ]*/
if (
(!parseHexString(uuid_string + 0, 4, uuid + 0)) ||
(uuid_string[8] != '-') ||
(!parseHexString(uuid_string + 9, 2, uuid + 4)) ||
(uuid_string[13] != '-') ||
(!parseHexString(uuid_string + 14, 2, uuid + 6)) ||
(uuid_string[18] != '-') ||
(!parseHexString(uuid_string + 19, 2, uuid + 8)) ||
(uuid_string[23] != '-') ||
(!parseHexString(uuid_string + 24, 6, uuid + 10))
)
{
LogError("const char* uuid_string=%s cannot be parsed at UUID_T", uuid_string);
result = UUID_FROM_STRING_RESULT_INVALID_DATA;
}
else
{
/*Codes_SRS_UUID_STRING_02_006: [ uuid_from_string shall convert the hex digits to the bytes of uuid, succeed and return UUID_FROM_STRING_RESULT_OK. ]*/
result = UUID_FROM_STRING_RESULT_OK;
}
}
return result;
}