diff options
author | Marc-André Lemburg <mal@egenix.com> | 2000-06-14 09:18:32 (GMT) |
---|---|---|
committer | Marc-André Lemburg <mal@egenix.com> | 2000-06-14 09:18:32 (GMT) |
commit | 60bc809d9a80ec12530d224cc680bae42c4de285 (patch) | |
tree | d3d97df20640c41fe39fa465397a3836026c3765 /Objects/unicodeobject.c | |
parent | bddf502a1f07d902f0d80aa268d3f1e838474c31 (diff) | |
download | cpython-60bc809d9a80ec12530d224cc680bae42c4de285.zip cpython-60bc809d9a80ec12530d224cc680bae42c4de285.tar.gz cpython-60bc809d9a80ec12530d224cc680bae42c4de285.tar.bz2 |
Marc-Andre Lemburg <mal@lemburg.com>:
Added code so that .isXXX() testing returns 0 for emtpy strings.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index eaa381b..bfc59dd 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3306,6 +3306,10 @@ unicode_islower(PyUnicodeObject *self, PyObject *args) if (PyUnicode_GET_SIZE(self) == 1) return PyInt_FromLong(Py_UNICODE_ISLOWER(*p) != 0); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { @@ -3339,6 +3343,10 @@ unicode_isupper(PyUnicodeObject *self, PyObject *args) if (PyUnicode_GET_SIZE(self) == 1) return PyInt_FromLong(Py_UNICODE_ISUPPER(*p) != 0); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { @@ -3374,6 +3382,10 @@ unicode_istitle(PyUnicodeObject *self, PyObject *args) return PyInt_FromLong((Py_UNICODE_ISTITLE(*p) != 0) || (Py_UNICODE_ISUPPER(*p) != 0)); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); cased = 0; previous_is_cased = 0; @@ -3418,6 +3430,10 @@ unicode_isspace(PyUnicodeObject *self, PyObject *args) Py_UNICODE_ISSPACE(*p)) return PyInt_FromLong(1); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISSPACE(*p)) @@ -3446,6 +3462,10 @@ unicode_isdecimal(PyUnicodeObject *self, PyObject *args) Py_UNICODE_ISDECIMAL(*p)) return PyInt_FromLong(1); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISDECIMAL(*p)) @@ -3474,6 +3494,10 @@ unicode_isdigit(PyUnicodeObject *self, PyObject *args) Py_UNICODE_ISDIGIT(*p)) return PyInt_FromLong(1); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISDIGIT(*p)) @@ -3502,6 +3526,10 @@ unicode_isnumeric(PyUnicodeObject *self, PyObject *args) Py_UNICODE_ISNUMERIC(*p)) return PyInt_FromLong(1); + /* Special case for empty strings */ + if (PyString_GET_SIZE(self) == 0) + return PyInt_FromLong(0); + e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISNUMERIC(*p)) |