diff options
author | INADA Naoki <methane@users.noreply.github.com> | 2018-01-27 05:06:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-27 05:06:21 (GMT) |
commit | a49ac9902903a798fab4970ccf563c531199c3f8 (patch) | |
tree | 56390f8d6849446b23d3d2a152c6197fc724ae70 /Objects/unicodeobject.c | |
parent | 85527cf50a9a4eecaca4022f7c6cb9e0bae1fa5f (diff) | |
download | cpython-a49ac9902903a798fab4970ccf563c531199c3f8.zip cpython-a49ac9902903a798fab4970ccf563c531199c3f8.tar.gz cpython-a49ac9902903a798fab4970ccf563c531199c3f8.tar.bz2 |
bpo-32677: Add .isascii() to str, bytes and bytearray (GH-5342)
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 0733011..4b90cc3 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -11612,6 +11612,25 @@ unicode_index(PyObject *self, PyObject *args) } /*[clinic input] +str.isascii as unicode_isascii + +Return True if all characters in the string are ASCII, False otherwise. + +ASCII characters have code points in the range U+0000-U+007F. +Empty string is ASCII too. +[clinic start generated code]*/ + +static PyObject * +unicode_isascii_impl(PyObject *self) +/*[clinic end generated code: output=c5910d64b5a8003f input=5a43cbc6399621d5]*/ +{ + if (PyUnicode_READY(self) == -1) { + return NULL; + } + return PyBool_FromLong(PyUnicode_IS_ASCII(self)); +} + +/*[clinic input] str.islower as unicode_islower Return True if the string is a lowercase string, False otherwise. @@ -13801,6 +13820,7 @@ static PyMethodDef unicode_methods[] = { UNICODE_UPPER_METHODDEF {"startswith", (PyCFunction) unicode_startswith, METH_VARARGS, startswith__doc__}, {"endswith", (PyCFunction) unicode_endswith, METH_VARARGS, endswith__doc__}, + UNICODE_ISASCII_METHODDEF UNICODE_ISLOWER_METHODDEF UNICODE_ISUPPER_METHODDEF UNICODE_ISTITLE_METHODDEF |