in sdk/src/azure/core/az_json_token.c [277:326]
AZ_NODISCARD static az_result _az_json_token_get_string_helper(
az_span source,
char* destination,
int32_t destination_max_size,
int32_t* dest_idx,
bool* next_char_escaped)
{
int32_t source_size = az_span_size(source);
uint8_t* source_ptr = az_span_ptr(source);
for (int32_t i = 0; i < source_size; i++)
{
if (*dest_idx >= destination_max_size)
{
return AZ_ERROR_NOT_ENOUGH_SPACE;
}
uint8_t token_byte = source_ptr[i];
if (token_byte == '\\' || *next_char_escaped)
{
if (*next_char_escaped)
{
token_byte = _az_json_unescape_single_byte(token_byte);
}
else
{
i++;
if (i >= source_size)
{
*next_char_escaped = true;
break;
}
token_byte = _az_json_unescape_single_byte(source_ptr[i]);
}
*next_char_escaped = false;
// TODO: Characters escaped in the form of \uXXXX where XXXX is the UTF-16 code point, is
// not currently supported.
// To do this, we need to encode UTF-16 codepoints (including surrogate pairs) into UTF-8.
if (token_byte == 'u')
{
return AZ_ERROR_NOT_IMPLEMENTED;
}
}
destination[*dest_idx] = (char)token_byte;
*dest_idx = *dest_idx + 1;
}
return AZ_OK;
}