summaryrefslogtreecommitdiffstats
path: root/Objects/stringobject.c
diff options
context:
space:
mode:
authorMarc-André Lemburg <mal@egenix.com>2000-06-14 09:18:32 (GMT)
committerMarc-André Lemburg <mal@egenix.com>2000-06-14 09:18:32 (GMT)
commit60bc809d9a80ec12530d224cc680bae42c4de285 (patch)
treed3d97df20640c41fe39fa465397a3836026c3765 /Objects/stringobject.c
parentbddf502a1f07d902f0d80aa268d3f1e838474c31 (diff)
downloadcpython-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/stringobject.c')
-rw-r--r--Objects/stringobject.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/stringobject.c b/Objects/stringobject.c
index 5d754b0..a254019 100644
--- a/Objects/stringobject.c
+++ b/Objects/stringobject.c
@@ -1927,6 +1927,10 @@ string_isspace(PyStringObject *self, PyObject *args)
isspace(*p))
return PyInt_FromLong(1);
+ /* Special case for empty strings */
+ if (PyString_GET_SIZE(self) == 0)
+ return PyInt_FromLong(0);
+
e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isspace(*p))
@@ -1956,6 +1960,10 @@ string_isdigit(PyStringObject *self, PyObject *args)
isdigit(*p))
return PyInt_FromLong(1);
+ /* Special case for empty strings */
+ if (PyString_GET_SIZE(self) == 0)
+ return PyInt_FromLong(0);
+
e = p + PyString_GET_SIZE(self);
for (; p < e; p++) {
if (!isdigit(*p))
@@ -1985,6 +1993,10 @@ string_islower(PyStringObject *self, PyObject *args)
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(islower(*p) != 0);
+ /* Special case for empty strings */
+ if (PyString_GET_SIZE(self) == 0)
+ return PyInt_FromLong(0);
+
e = p + PyString_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
@@ -2017,6 +2029,10 @@ string_isupper(PyStringObject *self, PyObject *args)
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(isupper(*p) != 0);
+ /* Special case for empty strings */
+ if (PyString_GET_SIZE(self) == 0)
+ return PyInt_FromLong(0);
+
e = p + PyString_GET_SIZE(self);
cased = 0;
for (; p < e; p++) {
@@ -2050,6 +2066,10 @@ string_istitle(PyStringObject *self, PyObject *args)
if (PyString_GET_SIZE(self) == 1)
return PyInt_FromLong(isupper(*p) != 0);
+ /* Special case for empty strings */
+ if (PyString_GET_SIZE(self) == 0)
+ return PyInt_FromLong(0);
+
e = p + PyString_GET_SIZE(self);
cased = 0;
previous_is_cased = 0;