[Python-checkins] python/dist/src/Modules unicodedata.c, 2.31, 2.32 unicodedata_db.h, 1.10, 1.11

perky at users.sourceforge.net perky at users.sourceforge.net
Wed Aug 4 09:38:37 CEST 2004


Update of /cvsroot/python/python/dist/src/Modules
In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1744/Modules

Modified Files:
	unicodedata.c unicodedata_db.h 
Log Message:
SF #989185: Drop unicode.iswide() and unicode.width() and add
unicodedata.east_asian_width().  You can still implement your own
simple width() function using it like this:
    def width(u):
        w = 0
        for c in unicodedata.normalize('NFC', u):
            cwidth = unicodedata.east_asian_width(c)
            if cwidth in ('W', 'F'): w += 2
            else: w += 1
        return w


Index: unicodedata.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/unicodedata.c,v
retrieving revision 2.31
retrieving revision 2.32
diff -C2 -d -r2.31 -r2.32
*** unicodedata.c	15 Jul 2004 04:30:25 -0000	2.31
--- unicodedata.c	4 Aug 2004 07:38:34 -0000	2.32
***************
*** 25,28 ****
--- 25,30 ----
  					   _PyUnicode_BidirectionalNames */
      const unsigned char mirrored;	/* true if mirrored in bidir mode */
+     const unsigned char east_asian_width;	/* index into
+ 						   _PyUnicode_EastAsianWidth */
  } _PyUnicode_DatabaseRecord;
  
***************
*** 206,209 ****
--- 208,229 ----
  
  static PyObject *
+ unicodedata_east_asian_width(PyObject *self, PyObject *args)
+ {
+     PyUnicodeObject *v;
+     int index;
+ 
+     if (!PyArg_ParseTuple(args, "O!:east_asian_width",
+ 			  &PyUnicode_Type, &v))
+ 	return NULL;
+     if (PyUnicode_GET_SIZE(v) != 1) {
+ 	PyErr_SetString(PyExc_TypeError,
+ 			"need a single Unicode character as parameter");
+ 	return NULL;
+     }
+     index = (int) _getrecord(v)->east_asian_width;
+     return PyString_FromString(_PyUnicode_EastAsianWidthNames[index]);
+ }
+ 
+ static PyObject *
  unicodedata_decomposition(PyObject *self, PyObject *args)
  {
***************
*** 872,875 ****
--- 892,896 ----
      {"combining", unicodedata_combining, METH_VARARGS},
      {"mirrored", unicodedata_mirrored, METH_VARARGS},
+     {"east_asian_width", unicodedata_east_asian_width, METH_VARARGS},
      {"decomposition",unicodedata_decomposition, METH_VARARGS},
      {"name", unicodedata_name, METH_VARARGS},

Index: unicodedata_db.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Modules/unicodedata_db.h,v
retrieving revision 1.10
retrieving revision 1.11
diff -C2 -d -r1.10 -r1.11
*** unicodedata_db.h	2 Jun 2004 16:49:12 -0000	1.10
--- unicodedata_db.h	4 Aug 2004 07:38:34 -0000	1.11
***************
*** 4,130 ****
  /* a list of unique database records */
  const _PyUnicode_DatabaseRecord _PyUnicode_Database_Records[] = {
!     {0, 0, 0, 0},
!     {13, 0, 15, 0},
!     {13, 0, 17, 0},
!     {13, 0, 16, 0},
!     {13, 0, 18, 0},
!     {10, 0, 18, 0},
!     {26, 0, 19, 0},
!     {26, 0, 11, 0},
[...2394 lines suppressed...]
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 
!     176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 176, 0, 0, 
  };
  



More information about the Python-checkins mailing list