Skip to content

Commit

Permalink
post-merge
Browse files Browse the repository at this point in the history
  • Loading branch information
picnixz committed Mar 1, 2025
1 parent dd36c99 commit b8fe3b6
Showing 1 changed file with 24 additions and 8 deletions.
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

0 comments on commit b8fe3b6

Please sign in to comment.