Lets do d6b1b849224288479fac7c617c10bc692f81395f first and split it into multiple commits, in a separate MR. I think it could be made simpler by introducing some helpers to avoid double pointers everywhere. Something like: ``` struct json_buffer { const WCHAR *str; UINT32 len; }; static void json_buffer_trim( struct json_buffer *json ) { static const WCHAR valid_whitespace[] = L" \t\n\r"; UINT32 start = 0, end = json->len; while (start < end && wcschr( valid_whitespace, json->str[start] )) start++; while (end > start && wcschr( valid_whitespace, json->str[end - 1] )) end--; json->str += start; json->len = end - start; } static BOOL json_buffer_take( struct json_buffer *json, const WCHAR *str ) { UINT len = wcslen( str ); if (json->len < len || wcsncmp( json->str, str, len )) return FALSE; json->str += len; json->len -= len; return TRUE; } static WCHAR json_buffer_next( struct json_buffer *json, const WCHAR *valid ) { WCHAR chr = *json->str; if (valid && !wcschr( valid, chr )) return 0; json->str++; json->len--; return chr; } ``` Regarding the string parsing I think it'd be better to avoid splitting validation / parsing, and instead validate while parsing. The helpers above should make it easy. The destination buffer could be allocated pessimistically with the maximum length, or through a quick run through (just to skip escaped quotes and stop on closing quote), similar to is currently there. -- https://gitlab.winehq.org/wine/wine/-/merge_requests/10263#note_133366