mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
remove some usage of Py_UNICODE_TOUPPER/LOWER
This commit is contained in:
parent
22ef4fa7e9
commit
21e0da228d
8 changed files with 21 additions and 27 deletions
|
@ -510,13 +510,14 @@ setup_context(Py_ssize_t stack_level, PyObject **filename, int *lineno,
|
|||
kind = PyUnicode_KIND(*filename);
|
||||
data = PyUnicode_DATA(*filename);
|
||||
|
||||
#define ascii_lower(c) ((c <= 127) ? Py_TOLOWER(c) : 0)
|
||||
/* if filename.lower().endswith((".pyc", ".pyo")): */
|
||||
if (len >= 4 &&
|
||||
PyUnicode_READ(kind, data, len-4) == '.' &&
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-3)) == 'p' &&
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-2)) == 'y' &&
|
||||
(Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'c' ||
|
||||
Py_UNICODE_TOLOWER(PyUnicode_READ(kind, data, len-1)) == 'o'))
|
||||
ascii_lower(PyUnicode_READ(kind, data, len-3)) == 'p' &&
|
||||
ascii_lower(PyUnicode_READ(kind, data, len-2)) == 'y' &&
|
||||
(ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'c' ||
|
||||
ascii_lower(PyUnicode_READ(kind, data, len-1)) == 'o'))
|
||||
{
|
||||
*filename = PyUnicode_Substring(*filename, 0,
|
||||
PyUnicode_GET_LENGTH(*filename)-1);
|
||||
|
|
|
@ -561,13 +561,14 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec,
|
|||
return -1;
|
||||
if (toupper) {
|
||||
Py_ssize_t t;
|
||||
/* XXX if the upper-case prefix is wider than the target
|
||||
buffer, the caller should have allocated a wider string,
|
||||
but currently doesn't. */
|
||||
for (t = 0; t < spec->n_prefix; ++t)
|
||||
PyUnicode_WRITE(kind, data, pos + t,
|
||||
Py_UNICODE_TOUPPER(
|
||||
PyUnicode_READ(kind, data, pos + t)));
|
||||
for (t = 0; t < spec->n_prefix; t++) {
|
||||
Py_UCS4 c = PyUnicode_READ(kind, data, pos + t);
|
||||
if (c > 127) {
|
||||
PyErr_SetString(PyExc_SystemError, "prefix not ASCII");
|
||||
return -1;
|
||||
}
|
||||
PyUnicode_WRITE(kind, data, pos + t, Py_TOUPPER(c));
|
||||
}
|
||||
}
|
||||
pos += spec->n_prefix;
|
||||
}
|
||||
|
@ -607,10 +608,14 @@ fill_number(PyObject *out, Py_ssize_t pos, const NumberFieldWidths *spec,
|
|||
}
|
||||
if (toupper) {
|
||||
Py_ssize_t t;
|
||||
for (t = 0; t < spec->n_grouped_digits; ++t)
|
||||
PyUnicode_WRITE(kind, data, pos + t,
|
||||
Py_UNICODE_TOUPPER(
|
||||
PyUnicode_READ(kind, data, pos + t)));
|
||||
for (t = 0; t < spec->n_grouped_digits; t++) {
|
||||
Py_UCS4 c = PyUnicode_READ(kind, data, pos + t);
|
||||
if (c > 127) {
|
||||
PyErr_SetString(PyExc_SystemError, "non-ascii grouped digit");
|
||||
return -1;
|
||||
}
|
||||
PyUnicode_WRITE(kind, data, pos + t, Py_TOUPPER(c));
|
||||
}
|
||||
}
|
||||
pos += spec->n_grouped_digits;
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue