You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 8f2d0f1
Browse filesBrowse the repository at this point in the historyBrowse files
[mypyc] Add librt.strings.toupper and tolower codepoint primitives (#21553)
6th PR of #21418.
This PR introduces two `i32 -> i32` case-conversion helpers, alongside
the existing classifiers.
**The constraint to flag**: A single i32 holds one codepoint, but some
Unicode case mappings expand to multiple e.g `'ß'.upper()` becomes
`'SS'`, `'fi'.upper()` becomes `'FI'` etc.
For those inputs the primitive _returns the input unchanged_; This is
the same split CPython makes between `Py_UNICODE_TOUPPER` (codepoint)
and `str.upper()` (string), with the former returning the **first
codepoint** of the expansion.
Users needing full Unicode case conversion should call `s.upper()` /
`s.lower()` on the string, for which we already have mypyc primitives
(#20948). For ASCII benchmarks, the codepoint primitives are ~5x faster
than their `str` counterparts, avoiding the 1-char allocation.
PyDoc_STR("Test whether a codepoint (i32) is a valid identifier start (XID_Start).")
1269
1281
},
1282
+
{"toupper", cp_toupper, METH_O,
1283
+
PyDoc_STR("Single-codepoint uppercase mapping for a codepoint (i32). Returns the input unchanged if the Unicode uppercase expands to multiple codepoints (e.g. U+00DF uppercases to \"SS\"); use str.upper() for full Unicode case conversion.")
1284
+
},
1285
+
{"tolower", cp_tolower, METH_O,
1286
+
PyDoc_STR("Single-codepoint lowercase mapping for a codepoint (i32). Returns the input unchanged if the Unicode lowercase expands to multiple codepoints; use str.lower() for full Unicode case conversion.")
0 commit comments