mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
bpo-32677: Add .isascii() to str, bytes and bytearray (GH-5342)
This commit is contained in:
parent
85527cf50a
commit
a49ac99029
13 changed files with 110 additions and 2 deletions
|
|
@ -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\
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue