I need to convert this c++ function into python:
bool validText(const char *text)
{
bool result = false;
while (*text)
{
if ((*text) & 0x80)
{
result = true;
text++;
}
else if ((*text >= 'a' && *text <= 'z' || *text >= 'A' && *text <= 'Z') ||
((*text) >= '0' && (*text) <= '9'))
{
result = true;
}
text++;
}
return result;
}
I understand that it is checking whether the string consists of chars with its int value is >= 128 or within the range of [a-zA-Z0-9].
My python version looks like:
def validText(text):
valid = False
for s in text:
c = ord(s)
if c >= 128:
valid = True
break
elif( (c>='a' and c<='z') or (c>='A' and c<='Z') (c>='0' and c<='9') ):
valid = True
break
return valid
I have two questions for this:
- Is my understanding of the c++ right?
- Is the python version right?
I can't find a proper string to test this, so not sure whether I am doing the right thing.