Mercurial > cpython-lru_cache-weakref
diff Objects/unicodeobject.c @ 23219:b08b51dce264 2.2
Backport the following changes:
Misc/NEWS 1.387->1.388
Lib/test/string_tests.py 1.10->1.11, 1.12->1.14,
Lib/test/test_unicode.py 1.50->1.51, 1.53->1.54, 1.55->1.56
Lib/test/test_string.py 1.15->1.16
Lib/string.py 1.61->1.63
Lib/test/test_userstring.py 1.5->1.6, 1.11, 1.12
Objects/stringobject.c 2.156->2.159
Objects/unicodeobject.c 2.137->2.139
Doc/lib/libstdtypes.tec 1.87->1.88
Add a method zfill to str, unicode and UserString
and change Lib/string.py accordingly
(see SF patch http://www.python.org/sf/536241)
This also adds Guido's fix to test_userstring.py
and the subinstance checks in test_string.py
and test_unicode.py.
| author | Walter Dörwald <walter@livinglogic.de> |
|---|---|
| date | Mon, 22 Apr 2002 11:57:06 +0000 |
| parents | 8600dba4f59d |
| children | dd350b639309 |
line wrap: on
line diff
--- a/Objects/unicodeobject.c Mon Apr 22 11:21:59 2002 +0000 +++ b/Objects/unicodeobject.c Mon Apr 22 11:57:06 2002 +0000 @@ -4810,7 +4810,6 @@ return fixup(self, fixupper); } -#if 0 static char zfill__doc__[] = "S.zfill(width) -> unicode\n\ \n\ @@ -4828,14 +4827,24 @@ return NULL; if (self->length >= width) { - Py_INCREF(self); - return (PyObject*) self; + if (PyUnicode_CheckExact(self)) { + Py_INCREF(self); + return (PyObject*) self; + } + else + return PyUnicode_FromUnicode( + PyUnicode_AS_UNICODE(self), + PyUnicode_GET_SIZE(self) + ); } fill = width - self->length; u = pad(self, fill, 0, '0'); + if (u == NULL) + return NULL; + if (u->str[fill] == '+' || u->str[fill] == '-') { /* move sign to beginning of string */ u->str[0] = u->str[fill]; @@ -4844,7 +4853,6 @@ return (PyObject*) u; } -#endif #if 0 static PyObject* @@ -4956,8 +4964,8 @@ {"isnumeric", (PyCFunction) unicode_isnumeric, METH_NOARGS, isnumeric__doc__}, {"isalpha", (PyCFunction) unicode_isalpha, METH_NOARGS, isalpha__doc__}, {"isalnum", (PyCFunction) unicode_isalnum, METH_NOARGS, isalnum__doc__}, + {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__}, #if 0 - {"zfill", (PyCFunction) unicode_zfill, METH_VARARGS, zfill__doc__}, {"capwords", (PyCFunction) unicode_capwords, METH_NOARGS, capwords__doc__}, #endif
