Skip to content

gh-129173: simplify PyCodec_XMLCharRefReplaceErrors logic #129894

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

Merged
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions Python/codecs.c
Original file line number Diff line number Diff line change
Expand Up @@ -730,18 +730,34 @@ codec_handler_write_unicode_hex(Py_UCS1 **p, Py_UCS4 ch)
}


/* Determine the number of digits for a decimal representation of codepoint ch
/*
* Determine the number of digits for a decimal representation of Unicode
* codepoint 'ch' (by design, Unicode codepoints are limited to 7 digits).
*/
static inline int
n_decimal_digits_for_codepoint(Py_UCS4 ch)
{
if (ch < 10) return 1;
if (ch < 100) return 2;
if (ch < 1000) return 3;
if (ch < 10000) return 4;
if (ch < 100000) return 5;
if (ch < 1000000) return 6;
if (ch < 10000000) return 7;
if (ch < 10) {
return 1;
}
if (ch < 100) {
return 2;
}
if (ch < 1000) {
return 3;
}
if (ch < 10000) {
return 4;
}
if (ch < 100000) {
return 5;
}
if (ch < 1000000) {
return 6;
}
if (ch < 10000000) {
return 7;
}
// Unicode codepoints are limited to 1114111 (7 decimal digits)
Py_UNREACHABLE();
}
Expand Down
Loading