-
Notifications
You must be signed in to change notification settings - Fork 274
Implement parsing of hexadecimal Unicode characters from JSON #4590
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,8 +46,15 @@ static std::string convert_TOK_STRING() | |
case 'r': result+='\r'; break; | ||
case 't': result+='\t'; break; | ||
case 'u': | ||
{ | ||
// Character in hexadecimal Unicode representation, in the format | ||
// \uABCD, i.e. the following four digits are part of this character. | ||
assert(p + 4 < yyjsontext + len - 1); | ||
std::string hex(++p, 4); | ||
result += std::stoi(hex, nullptr, 16); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this casts to a char (8-bit uint), so will only work for unicode characters <= 255 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is addressed in a follow-up PR: #4594 |
||
p += 3; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Comment that you're intentionally leaving |
||
break; | ||
} | ||
default:; /* an error */ | ||
} | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggest
p + 5 < yyjsontext + len
would be better -- we're checking for 5-byte string uXXXX being in range, after allThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I found the current version to be clearer: when pointing to
u
, if you advance by four steps (pointing to the last hex character), then you have to still be to the left of the last"
of the string. But I'm happy to change it in a follow-up PR if you think your version is more intuitive.