mirror of
https://github.com/python/cpython.git
synced 2025-07-31 23:23:11 +00:00
PyUnicode_DecodeCharmap() uses the new Unicode API
This commit is contained in:
parent
a98b28c1bf
commit
ebf3ba808e
1 changed files with 17 additions and 7 deletions
|
@ -7558,8 +7558,6 @@ PyUnicode_DecodeCharmap(const char *s,
|
||||||
Py_ssize_t extrachars = 0;
|
Py_ssize_t extrachars = 0;
|
||||||
PyObject *errorHandler = NULL;
|
PyObject *errorHandler = NULL;
|
||||||
PyObject *exc = NULL;
|
PyObject *exc = NULL;
|
||||||
Py_UNICODE *mapstring = NULL;
|
|
||||||
Py_ssize_t maplen = 0;
|
|
||||||
|
|
||||||
/* Default to Latin-1 */
|
/* Default to Latin-1 */
|
||||||
if (mapping == NULL)
|
if (mapping == NULL)
|
||||||
|
@ -7573,16 +7571,27 @@ PyUnicode_DecodeCharmap(const char *s,
|
||||||
outpos = 0;
|
outpos = 0;
|
||||||
e = s + size;
|
e = s + size;
|
||||||
if (PyUnicode_CheckExact(mapping)) {
|
if (PyUnicode_CheckExact(mapping)) {
|
||||||
mapstring = PyUnicode_AS_UNICODE(mapping);
|
Py_ssize_t maplen;
|
||||||
maplen = PyUnicode_GET_SIZE(mapping);
|
enum PyUnicode_Kind kind;
|
||||||
|
void *data;
|
||||||
|
Py_UCS4 x;
|
||||||
|
|
||||||
|
if (PyUnicode_READY(mapping) < 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
maplen = PyUnicode_GET_LENGTH(mapping);
|
||||||
|
data = PyUnicode_DATA(mapping);
|
||||||
|
kind = PyUnicode_KIND(mapping);
|
||||||
while (s < e) {
|
while (s < e) {
|
||||||
unsigned char ch = *s;
|
unsigned char ch = *s;
|
||||||
Py_UNICODE x = 0xfffe; /* illegal value */
|
|
||||||
|
|
||||||
if (ch < maplen)
|
if (ch < maplen)
|
||||||
x = mapstring[ch];
|
x = PyUnicode_READ(kind, data, ch);
|
||||||
|
else
|
||||||
|
x = 0xfffe; /* invalid value */
|
||||||
|
|
||||||
if (x == 0xfffe) {
|
if (x == 0xfffe)
|
||||||
|
{
|
||||||
/* undefined mapping */
|
/* undefined mapping */
|
||||||
startinpos = s-starts;
|
startinpos = s-starts;
|
||||||
endinpos = startinpos+1;
|
endinpos = startinpos+1;
|
||||||
|
@ -7595,6 +7604,7 @@ PyUnicode_DecodeCharmap(const char *s,
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unicode_putchar(&v, &outpos, x) < 0)
|
if (unicode_putchar(&v, &outpos, x) < 0)
|
||||||
goto onError;
|
goto onError;
|
||||||
++s;
|
++s;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue