summaryrefslogtreecommitdiffstats
path: root/Modules/_json.c
diff options
context:
space:
mode:
authorVictor Stinner <victor.stinner@gmail.com>2012-10-30 00:42:39 (GMT)
committerVictor Stinner <victor.stinner@gmail.com>2012-10-30 00:42:39 (GMT)
commit76df43de30f40b5cc1de9d36a5a083dd8bd8cb27 (patch)
treebe245b62c632a103851fa69d447e8d89e3ac782f /Modules/_json.c
parenta5e7cd06bb314f338eff3e2ef948ef35bed4487b (diff)
downloadcpython-76df43de30f40b5cc1de9d36a5a083dd8bd8cb27.zip
cpython-76df43de30f40b5cc1de9d36a5a083dd8bd8cb27.tar.gz
cpython-76df43de30f40b5cc1de9d36a5a083dd8bd8cb27.tar.bz2
Issue #16330: Use surrogate-related macros
Patch written by Serhiy Storchaka.
Diffstat (limited to 'Modules/_json.c')
-rw-r--r--Modules/_json.c21
1 files changed, 10 insertions, 11 deletions
diff --git a/Modules/_json.c b/Modules/_json.c
index fb8bd59..2538b05 100644
--- a/Modules/_json.c
+++ b/Modules/_json.c
@@ -174,14 +174,13 @@ ascii_escape_unichar(Py_UCS4 c, unsigned char *output, Py_ssize_t chars)
default:
if (c >= 0x10000) {
/* UTF-16 surrogate pair */
- Py_UCS4 v = c - 0x10000;
- c = 0xd800 | ((v >> 10) & 0x3ff);
+ Py_UCS4 v = Py_UNICODE_HIGH_SURROGATE(c);
output[chars++] = 'u';
- output[chars++] = Py_hexdigits[(c >> 12) & 0xf];
- output[chars++] = Py_hexdigits[(c >> 8) & 0xf];
- output[chars++] = Py_hexdigits[(c >> 4) & 0xf];
- output[chars++] = Py_hexdigits[(c ) & 0xf];
- c = 0xdc00 | (v & 0x3ff);
+ output[chars++] = Py_hexdigits[(v >> 12) & 0xf];
+ output[chars++] = Py_hexdigits[(v >> 8) & 0xf];
+ output[chars++] = Py_hexdigits[(v >> 4) & 0xf];
+ output[chars++] = Py_hexdigits[(v ) & 0xf];
+ c = Py_UNICODE_LOW_SURROGATE(c);
output[chars++] = '\\';
}
output[chars++] = 'u';
@@ -431,7 +430,7 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
}
}
/* Surrogate pair */
- if ((c & 0xfc00) == 0xd800) {
+ if (Py_UNICODE_IS_HIGH_SURROGATE(c)) {
Py_UCS4 c2 = 0;
if (end + 6 >= len) {
raise_errmsg("Unpaired high surrogate", pystr, end - 5);
@@ -462,13 +461,13 @@ scanstring_unicode(PyObject *pystr, Py_ssize_t end, int strict, Py_ssize_t *next
goto bail;
}
}
- if ((c2 & 0xfc00) != 0xdc00) {
+ if (!Py_UNICODE_IS_LOW_SURROGATE(c2)) {
raise_errmsg("Unpaired high surrogate", pystr, end - 5);
goto bail;
}
- c = 0x10000 + (((c - 0xd800) << 10) | (c2 - 0xdc00));
+ c = Py_UNICODE_JOIN_SURROGATES(c, c2);
}
- else if ((c & 0xfc00) == 0xdc00) {
+ else if (Py_UNICODE_IS_LOW_SURROGATE(c)) {
raise_errmsg("Unpaired low surrogate", pystr, end - 5);
goto bail;
}