[Python-checkins] python/dist/src/Objects unicodectype.c, 2.15, 2.16 unicodeobject.c, 2.218, 2.219 unicodetype_db.h, 1.8, 1.9

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


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

Modified Files:
	unicodectype.c unicodeobject.c unicodetype_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: unicodectype.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodectype.c,v
retrieving revision 2.15
retrieving revision 2.16
diff -C2 -d -r2.15 -r2.16
*** unicodectype.c	2 Jun 2004 16:49:16 -0000	2.15
--- unicodectype.c	4 Aug 2004 07:38:34 -0000	2.16
***************
*** 20,24 ****
  #define TITLE_MASK 0x40
  #define UPPER_MASK 0x80
- #define WIDE_MASK 0x100
  
  typedef struct {
--- 20,23 ----
***************
*** 324,336 ****
  }
  
- /* 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
  
--- 323,326 ----

Index: unicodeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodeobject.c,v
retrieving revision 2.218
retrieving revision 2.219
diff -C2 -d -r2.218 -r2.219
*** unicodeobject.c	23 Jul 2004 16:13:25 -0000	2.218
--- unicodeobject.c	4 Aug 2004 07:38:35 -0000	2.219
***************
*** 703,727 ****
  }
  
- int PyUnicode_GetWidth(PyObject *unicode)
- {
-     const Py_UNICODE *p, *e;
-     int width;
- 
-     if (!PyUnicode_Check(unicode)) {
- 	PyErr_BadArgument();
- 	return -1;
-     }
- 
-     p = PyUnicode_AS_UNICODE(unicode);
-     e = p + PyUnicode_GET_SIZE(unicode);
-     for (width = 0; p < e; p++)
- 	if (Py_UNICODE_ISWIDE(*p))
- 	    width += 2;
- 	else
- 	    width++;
- 
-     return width;
- }
- 
  const char *PyUnicode_GetDefaultEncoding(void)
  {
--- 703,706 ----
***************
*** 5437,5469 ****
  }
  
- PyDoc_STRVAR(iswide__doc__,
- "S.iswide() -> bool\n\
- \n\
- Return True if all characters in S are wide width\n\
- and there is at least one character in S, False otherwise.");
- 
- static PyObject*
- unicode_iswide(PyUnicodeObject *self)
- {
-     register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self);
-     register const Py_UNICODE *e;
- 
-     /* Shortcut for single character strings */
-     if (PyUnicode_GET_SIZE(self) == 1 &&
- 	Py_UNICODE_ISWIDE(*p))
- 	Py_RETURN_TRUE;
- 
-     /* Special case for empty strings */
-     if (PyString_GET_SIZE(self) == 0)
- 	Py_RETURN_FALSE;
- 
-     e = p + PyUnicode_GET_SIZE(self);
-     for (; p < e; p++) {
- 	if (!Py_UNICODE_ISWIDE(*p))
- 	    Py_RETURN_FALSE;
-     }
-     Py_RETURN_TRUE;
- }
- 
  PyDoc_STRVAR(join__doc__,
  "S.join(sequence) -> unicode\n\
--- 5416,5419 ----
***************
*** 6077,6095 ****
  }
  
- PyDoc_STRVAR(width__doc__,
- "S.width() -> unicode\n\
- \n\
- Return a fixed-width representation length of S.");
- 
- static PyObject*
- unicode_width(PyObject *self)
- {
-     int width = PyUnicode_GetWidth(self);
-     if (width == -1)
- 	return NULL;
-     else
- 	return PyInt_FromLong((long)width);
- }
- 
  PyDoc_STRVAR(zfill__doc__,
  "S.zfill(width) -> unicode\n\
--- 6027,6030 ----
***************
*** 6256,6261 ****
      {"isalpha", (PyCFunction) unicode_isalpha, METH_NOARGS, isalpha__doc__},
      {"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__},
-     {"iswide", (PyCFunction) unicode_iswide, METH_NOARGS, iswide__doc__},
-     {"width", (PyCFunction) unicode_width, METH_NOARGS, width__doc__},
      {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__},
  #if 0
--- 6191,6194 ----

Index: unicodetype_db.h
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/unicodetype_db.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -C2 -d -r1.8 -r1.9
*** unicodetype_db.h	2 Jun 2004 16:49:16 -0000	1.8
--- unicodetype_db.h	4 Aug 2004 07:38:35 -0000	1.9
***************
*** 88,92 ****
      {0, 48, 0, 0, 0, 129},
      {65488, 0, 65488, 0, 0, 9},
-     {0, 0, 0, 0, 0, 257},
      {65477, 0, 65477, 0, 0, 9},
      {8, 0, 8, 0, 0, 9},
--- 88,91 ----
***************
*** 115,119 ****
      {0, 16, 0, 0, 0, 0},
      {65520, 0, 65520, 0, 0, 0},
[...978 lines suppressed...]
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
!     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
***************
*** 1147,1151 ****
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
!     1, 1, 1, 1, 1, 0, 0, 
  };
  
--- 1086,1090 ----
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
!     1, 1, 1, 1, 1, 1, 0, 0, 
  };
  



More information about the Python-checkins mailing list