*/
-static const char *hexdigits = "0123456789abcdef";
-
PyObject *
PyUnicode_EncodeUnicodeEscape(const Py_UNICODE *s,
Py_ssize_t size)
else if (ch >= 0x10000) {
*p++ = '\\';
*p++ = 'U';
- *p++ = hexdigits[(ch >> 28) & 0x0000000F];
- *p++ = hexdigits[(ch >> 24) & 0x0000000F];
- *p++ = hexdigits[(ch >> 20) & 0x0000000F];
- *p++ = hexdigits[(ch >> 16) & 0x0000000F];
- *p++ = hexdigits[(ch >> 12) & 0x0000000F];
- *p++ = hexdigits[(ch >> 8) & 0x0000000F];
- *p++ = hexdigits[(ch >> 4) & 0x0000000F];
- *p++ = hexdigits[ch & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 28) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 24) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 20) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 16) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 12) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 8) & 0x0000000F];
+ *p++ = Py_hexdigits[(ch >> 4) & 0x0000000F];
+ *p++ = Py_hexdigits[ch & 0x0000000F];
continue;
}
#else
ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
*p++ = '\\';
*p++ = 'U';
- *p++ = hexdigits[(ucs >> 28) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 24) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 20) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 16) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 12) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 8) & 0x0000000F];
- *p++ = hexdigits[(ucs >> 4) & 0x0000000F];
- *p++ = hexdigits[ucs & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 28) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 24) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 20) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 16) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 12) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 8) & 0x0000000F];
+ *p++ = Py_hexdigits[(ucs >> 4) & 0x0000000F];
+ *p++ = Py_hexdigits[ucs & 0x0000000F];
continue;
}
/* Fall through: isolated surrogates are copied as-is */
if (ch >= 256) {
*p++ = '\\';
*p++ = 'u';
- *p++ = hexdigits[(ch >> 12) & 0x000F];
- *p++ = hexdigits[(ch >> 8) & 0x000F];
- *p++ = hexdigits[(ch >> 4) & 0x000F];
- *p++ = hexdigits[ch & 0x000F];
+ *p++ = Py_hexdigits[(ch >> 12) & 0x000F];
+ *p++ = Py_hexdigits[(ch >> 8) & 0x000F];
+ *p++ = Py_hexdigits[(ch >> 4) & 0x000F];
+ *p++ = Py_hexdigits[ch & 0x000F];
}
/* Map special whitespace to '\t', \n', '\r' */
else if (ch < ' ' || ch >= 0x7F) {
*p++ = '\\';
*p++ = 'x';
- *p++ = hexdigits[(ch >> 4) & 0x000F];
- *p++ = hexdigits[ch & 0x000F];
+ *p++ = Py_hexdigits[(ch >> 4) & 0x000F];
+ *p++ = Py_hexdigits[ch & 0x000F];
}
/* Copy everything else as-is */
if (ch >= 0x10000) {
*p++ = '\\';
*p++ = 'U';
- *p++ = hexdigits[(ch >> 28) & 0xf];
- *p++ = hexdigits[(ch >> 24) & 0xf];
- *p++ = hexdigits[(ch >> 20) & 0xf];
- *p++ = hexdigits[(ch >> 16) & 0xf];
- *p++ = hexdigits[(ch >> 12) & 0xf];
- *p++ = hexdigits[(ch >> 8) & 0xf];
- *p++ = hexdigits[(ch >> 4) & 0xf];
- *p++ = hexdigits[ch & 15];
+ *p++ = Py_hexdigits[(ch >> 28) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 24) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 20) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 16) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 12) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 8) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 4) & 0xf];
+ *p++ = Py_hexdigits[ch & 15];
}
else
#else
ucs = (((ch & 0x03FF) << 10) | (ch2 & 0x03FF)) + 0x00010000;
*p++ = '\\';
*p++ = 'U';
- *p++ = hexdigits[(ucs >> 28) & 0xf];
- *p++ = hexdigits[(ucs >> 24) & 0xf];
- *p++ = hexdigits[(ucs >> 20) & 0xf];
- *p++ = hexdigits[(ucs >> 16) & 0xf];
- *p++ = hexdigits[(ucs >> 12) & 0xf];
- *p++ = hexdigits[(ucs >> 8) & 0xf];
- *p++ = hexdigits[(ucs >> 4) & 0xf];
- *p++ = hexdigits[ucs & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 28) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 24) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 20) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 16) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 12) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 8) & 0xf];
+ *p++ = Py_hexdigits[(ucs >> 4) & 0xf];
+ *p++ = Py_hexdigits[ucs & 0xf];
continue;
}
/* Fall through: isolated surrogates are copied as-is */
if (ch >= 256) {
*p++ = '\\';
*p++ = 'u';
- *p++ = hexdigits[(ch >> 12) & 0xf];
- *p++ = hexdigits[(ch >> 8) & 0xf];
- *p++ = hexdigits[(ch >> 4) & 0xf];
- *p++ = hexdigits[ch & 15];
+ *p++ = Py_hexdigits[(ch >> 12) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 8) & 0xf];
+ *p++ = Py_hexdigits[(ch >> 4) & 0xf];
+ *p++ = Py_hexdigits[ch & 15];
}
/* Copy everything else as-is */
else
else if (ch < ' ' || ch == 0x7F) {
PyUnicode_WRITE(okind, odata, o++, '\\');
PyUnicode_WRITE(okind, odata, o++, 'x');
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 4) & 0x000F]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[ch & 0x000F]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]);
}
/* Copy ASCII characters as-is */
if (ch <= 0xff) {
PyUnicode_WRITE(okind, odata, o++, '\\');
PyUnicode_WRITE(okind, odata, o++, 'x');
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 4) & 0x000F]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[ch & 0x000F]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0x000F]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0x000F]);
}
/* Map 21-bit characters to '\U00xxxxxx' */
else if (ch >= 0x10000) {
PyUnicode_WRITE(okind, odata, o++, '\\');
PyUnicode_WRITE(okind, odata, o++, 'U');
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 28) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 24) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 20) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 16) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 12) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 8) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 4) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[ch & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 28) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 24) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 20) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 16) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]);
}
/* Map 16-bit characters to '\uxxxx' */
else {
PyUnicode_WRITE(okind, odata, o++, '\\');
PyUnicode_WRITE(okind, odata, o++, 'u');
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 12) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 8) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[(ch >> 4) & 0xF]);
- PyUnicode_WRITE(okind, odata, o++, hexdigits[ch & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 12) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 8) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[(ch >> 4) & 0xF]);
+ PyUnicode_WRITE(okind, odata, o++, Py_hexdigits[ch & 0xF]);
}
}
/* Copy characters as-is */