bpo-32677: Add .isascii() to str, bytes and bytearray (GH-5342)

This commit is contained in:
INADA Naoki 2018-01-27 14:06:21 +09:00 committed by GitHub
parent 85527cf50a
commit a49ac99029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 110 additions and 2 deletions

View file

@ -92,6 +92,26 @@ _Py_bytes_isalnum(const char *cptr, Py_ssize_t len)
}
PyDoc_STRVAR_shared(_Py_isascii__doc__,
"B.isascii() -> bool\n\
\n\
Return True if B is empty or all characters in B are ASCII,\n\
False otherwise.");
PyObject*
_Py_bytes_isascii(const char *cptr, Py_ssize_t len)
{
const unsigned char *p = (unsigned char *) cptr;
const unsigned char *e = p + len;
for (; p < e; p++) {
if (*p >= 128) {
Py_RETURN_FALSE;
}
}
Py_RETURN_TRUE;
}
PyDoc_STRVAR_shared(_Py_isdigit__doc__,
"B.isdigit() -> bool\n\
\n\