Skip to content

Commit 456902d

Browse files
committed
Implement islower method
1 parent 0b944f2 commit 456902d

2 files changed

Lines changed: 37 additions & 1 deletion

File tree

src/cstring.c

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,27 @@ PyObject *cstring_isdigit(PyObject *self, PyObject *args) {
392392
Py_RETURN_TRUE;
393393
}
394394

395+
PyDoc_STRVAR(islower__doc__, "");
396+
PyObject *cstring_islower(PyObject *self, PyObject *args) {
397+
const char *p = CSTRING_VALUE(self);
398+
while(*p) {
399+
if(isalpha(*p)) {
400+
if(!islower(*p))
401+
Py_RETURN_FALSE;
402+
++p;
403+
while(*p) {
404+
if(isalpha(*p) && !islower(*p))
405+
Py_RETURN_FALSE;
406+
++p;
407+
}
408+
/* at least one lc alpha and no uc alphas */
409+
Py_RETURN_TRUE;
410+
}
411+
++p;
412+
}
413+
Py_RETURN_FALSE;
414+
}
415+
395416
PyDoc_STRVAR(rfind__doc__, "");
396417
PyObject *cstring_rfind(PyObject *self, PyObject *args) {
397418
struct _substr_params params;
@@ -476,7 +497,7 @@ static PyMethodDef cstring_methods[] = {
476497
/* TODO: isdecimal */
477498
{"isdigit", cstring_isdigit, METH_VARARGS, isdigit__doc__},
478499
/* TODO: isidentifier */
479-
/* TODO: islower */
500+
{"islower", cstring_islower, METH_VARARGS, islower__doc__},
480501
/* TODO: isnumeric */
481502
/* TODO: isprintable */
482503
/* TODO: isspace */

test/test_methods.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,21 @@ def test_isdigit_False():
8383
assert target.isdigit() == False
8484

8585

86+
def test_islower_numeric():
87+
target = cstring('123')
88+
assert target.islower() == False
89+
90+
91+
def test_islower_alnum_lc():
92+
target = cstring('hello123')
93+
assert target.islower() == True
94+
95+
96+
def test_islower_alnum_uc():
97+
target = cstring('Hello123')
98+
assert target.islower() == False
99+
100+
86101
def test_rfind():
87102
target = cstring('hello')
88103
assert target.rfind('o') == 4

0 commit comments

Comments
 (0)