[Python-checkins] cpython: find_maxchar_surrogates() reuses surrogate macros

victor.stinner python-checkins at python.org
Tue Nov 22 03:36:25 CET 2011


http://hg.python.org/cpython/rev/8b25f0ff8e95
changeset:   73687:8b25f0ff8e95
user:        Victor Stinner <victor.stinner at haypocalc.com>
date:        Tue Nov 22 03:38:40 2011 +0100
summary:
  find_maxchar_surrogates() reuses surrogate macros

files:
  Objects/unicodeobject.c |  8 ++++----
  1 files changed, 4 insertions(+), 4 deletions(-)


diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c
--- a/Objects/unicodeobject.c
+++ b/Objects/unicodeobject.c
@@ -1308,12 +1308,12 @@
 #endif
         }
 #if SIZEOF_WCHAR_T == 2
-        if (*iter >= 0xD800 && *iter <= 0xDBFF
-            && (iter+1) < end && iter[1] >= 0xDC00 && iter[1] <= 0xDFFF)
+        if (Py_UNICODE_IS_HIGH_SURROGATE(iter[0])
+            && (iter+1) < end
+            && Py_UNICODE_IS_LOW_SURROGATE(iter[1]))
         {
             Py_UCS4 surrogate_val;
-            surrogate_val = (((iter[0] & 0x3FF)<<10)
-                             | (iter[1] & 0x3FF)) + 0x10000;
+            surrogate_val = Py_UNICODE_JOIN_SURROGATES(iter[0], iter[1]);
             ++(*num_surrogates);
             if (surrogate_val > *maxchar)
                 *maxchar = surrogate_val;

-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list