From 2e9cfadd7c1a70ae77073b063c5a3fb825be86d7 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Sun, 20 Nov 2011 18:40:27 +0100 Subject: [PATCH] Reuse surrogate macros in UTF-16 decoder --- Objects/unicodeobject.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 68e05866361..b02adeed91a 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5339,13 +5339,12 @@ PyUnicode_DecodeUTF16Stateful(const char *s, endinpos = ((const char *)e) + 1 - starts; goto utf16Error; } - if (0xD800 <= ch && ch <= 0xDBFF) { - Py_UNICODE ch2 = (q[ihi] << 8) | q[ilo]; + if (Py_UNICODE_IS_HIGH_SURROGATE(ch)) { + Py_UCS4 ch2 = (q[ihi] << 8) | q[ilo]; q += 2; - if (0xDC00 <= ch2 && ch2 <= 0xDFFF) { + if (Py_UNICODE_IS_LOW_SURROGATE(ch2)) { if (unicode_putchar(&unicode, &outpos, - (((ch & 0x3FF)<<10) | - (ch2 & 0x3FF)) + 0x10000) < 0) + Py_UNICODE_JOIN_SURROGATES(ch, ch2)) < 0) goto onError; continue; }