summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2011-08-22 17:03:25 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2011-08-22 17:03:25 (GMT)
commit8c9375bb5996417f737e63f5080fc8b6eb886a77 (patch)
tree3b6bf8c1b1984a0c952768631b41e7b36f65642b /Include
parent3d1706fa83be3d60562098a9e86eb1f8f778a35c (diff)
downloadcpython-8c9375bb5996417f737e63f5080fc8b6eb886a77.zip
cpython-8c9375bb5996417f737e63f5080fc8b6eb886a77.tar.gz
cpython-8c9375bb5996417f737e63f5080fc8b6eb886a77.tar.bz2
#10542: Add 4 macros to work with surrogates: Py_UNICODE_IS_SURROGATE, Py_UNICODE_IS_HIGH_SURROGATE, Py_UNICODE_IS_LOW_SURROGATE, Py_UNICODE_JOIN_SURROGATES.
Diffstat (limited to 'Include')
-rw-r--r--Include/unicodeobject.h9
1 files changed, 9 insertions, 0 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h
index 44c1775..68298b0 100644
--- a/Include/unicodeobject.h
+++ b/Include/unicodeobject.h
@@ -362,6 +362,15 @@ typedef PY_UNICODE_TYPE Py_UNICODE;
for (i_ = 0; i_ < (length); i_++) t_[i_] = v_;\
} while (0)
+/* macros to work with surrogates */
+#define Py_UNICODE_IS_SURROGATE(ch) (0xD800 <= ch && ch <= 0xDFFF)
+#define Py_UNICODE_IS_HIGH_SURROGATE(ch) (0xD800 <= ch && ch <= 0xDBFF)
+#define Py_UNICODE_IS_LOW_SURROGATE(ch) (0xDC00 <= ch && ch <= 0xDFFF)
+/* Join two surrogate characters and return a single Py_UCS4 value. */
+#define Py_UNICODE_JOIN_SURROGATES(high, low) \
+ (((((Py_UCS4)(high) & 0x03FF) << 10) | \
+ ((Py_UCS4)(low) & 0x03FF)) + 0x10000)
+
/* Check if substring matches at given offset. The offset must be
valid, and the substring must not be empty. */