- SF #962502: Add two more methods for unicode type; width() and
iswide() for east asian width manipulation. (Inspired by David
Goodger, Reviewed by Martin v. Loewis)
- Move _PyUnicode_TypeRecord.flags to the end of the struct so that
no padding is added for UCS-4 builds. (Suggested by Martin v. Loewis)
diff --git a/Objects/unicodectype.c b/Objects/unicodectype.c
index 7a330d9..d770bdb 100644
--- a/Objects/unicodectype.c
+++ b/Objects/unicodectype.c
@@ -19,14 +19,15 @@
 #define SPACE_MASK 0x20
 #define TITLE_MASK 0x40
 #define UPPER_MASK 0x80
+#define WIDE_MASK 0x100
 
 typedef struct {
-    const unsigned short flags;
     const Py_UNICODE upper;
     const Py_UNICODE lower;
     const Py_UNICODE title;
     const unsigned char decimal;
     const unsigned char digit;
+    const unsigned short flags;
 } _PyUnicode_TypeRecord;
 
 #include "unicodetype_db.h"
@@ -322,6 +323,15 @@
     return 1;
 }
 
+/* Returns 1 for Unicode characters having Full or Wide width, 0 otherwise */
+
+int _PyUnicode_IsWide(Py_UNICODE ch)
+{
+    const _PyUnicode_TypeRecord *ctype = gettyperecord(ch);
+
+    return (ctype->flags & WIDE_MASK) != 0;
+}
+
 #ifndef WANT_WCTYPE_FUNCTIONS
 
 /* Returns 1 for Unicode characters having the bidirectional type