{ PyObject *str, *sub; int result; /* Coerce the two arguments */ sub = PyUnicode_FromObject(element); if (!sub) { PyErr_SetString(PyExc_TypeError, "'in <string>' requires string as left operand"); return -1; } str = PyUnicode_FromObject(container); if (!str) { Py_DECREF(sub); return -1; } result = stringlib_contains_obj(str, sub); Py_DECREF(str); Py_DECREF(sub); return result;} /* Concat to string or Unicode object giving a new Unicode object. */ PyObject *PyUnicode_Concat(PyObject *left, PyObject *right){ PyUnicodeObject *u = NULL, *v = NULL, *w; /* Coerce the two arguments */ u = (PyUnicodeObject *)PyUnicode_FromObject(left); if (u == NULL) goto onError; v = (PyUnicodeObject *)PyUnicode_FromObject(right); if (v == NULL) goto onError; /* Shortcuts */ if (v == unicode_empty) { Py_DECREF(v); return (PyObject *)u; } if (u == unicode_empty) { Py_DECREF(u); return (PyObject *)v; } /* Concat the two Unicode strings */ w = _PyUnicode_New(u->length + v->length); if (w == NULL) goto onError; Py_UNICODE_COPY(w->str, u->str, u->length); Py_UNICODE_COPY(w->str + u->length, v->str, v->length); Py_DECREF(u); Py_DECREF(v); return (PyObject *)w; onError: Py_XDECREF(u); Py_XDECREF(v); return NULL;} PyDoc_STRVAR(count__doc__,"S.count(sub[, start[, end]]) -> int\n\\n\Return the number of non-overlapping occurrences of substring sub in\n\Unicode string S[start:end]. Optional arguments start and end are\n\interpreted as in slice notation."); static PyObject *unicode_count(PyUnicodeObject *self, PyObject *args){ PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *result; if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = (PyUnicodeObject *)PyUnicode_FromObject( (PyObject *)substring); if (substring == NULL) return NULL; FIX_START_END(self); result = PyInt_FromSsize_t( stringlib_count(self->str + start, end - start, substring->str, substring->length) ); Py_DECREF(substring); return result;} PyDoc_STRVAR(encode__doc__,"S.encode([encoding[,errors]]) -> string or unicode\n\\n\Encodes S using the codec registered for encoding. encoding defaults\n\to the default encoding. errors may be given to set a different error\n\handling scheme. Default is 'strict' meaning that encoding errors raise\n\a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\'xmlcharrefreplace' as well as any other name registered with\n\codecs.register_error that can handle UnicodeEncodeErrors."); static PyObject *unicode_encode(PyUnicodeObject *self, PyObject *args){ char *encoding = NULL; char *errors = NULL; PyObject *v; if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors)) return NULL; v = PyUnicode_AsEncodedObject((PyObject *)self, encoding, errors); if (v == NULL) goto onError; if (!PyString_Check(v) && !PyUnicode_Check(v)) { PyErr_Format(PyExc_TypeError, "encoder did not return a string/unicode object " "(type=%.400s)", v->ob_type->tp_name); Py_DECREF(v); return NULL; } return v; onError: return NULL;} PyDoc_STRVAR(decode__doc__,"S.decode([encoding[,errors]]) -> string or unicode\n\\n\Decodes S using the codec registered for encoding. encoding defaults\n\to the default encoding. errors may be given to set a different error\n\handling scheme. Default is 'strict' meaning that encoding errors raise\n\a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\as well as any other name registerd with codecs.register_error that is\n\able to handle UnicodeDecodeErrors."); static PyObject *unicode_decode(PyUnicodeObject *self, PyObject *args){ char *encoding = NULL; char *errors = NULL; PyObject *v; if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors)) return NULL; v = PyUnicode_AsDecodedObject((PyObject *)self, encoding, errors); if (v == NULL) goto onError; if (!PyString_Check(v) && !PyUnicode_Check(v)) { PyErr_Format(PyExc_TypeError, "decoder did not return a string/unicode object " "(type=%.400s)", v->ob_type->tp_name); Py_DECREF(v); return NULL; } return v; onError: return NULL;} PyDoc_STRVAR(expandtabs__doc__,"S.expandtabs([tabsize]) -> unicode\n\\n\Return a copy of S where all tab characters are expanded using spaces.\n\If tabsize is not given, a tab size of 8 characters is assumed."); static PyObject*unicode_expandtabs(PyUnicodeObject *self, PyObject *args){ Py_UNICODE *e; Py_UNICODE *p; Py_UNICODE *q; Py_ssize_t i, j; PyUnicodeObject *u; int tabsize = 8; if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize)) return NULL; /* First pass: determine size of output string */ i = j = 0; e = self->str + self->length; for (p = self->str; p < e; p++) if (*p == '\t') { if (tabsize > 0) j += tabsize - (j % tabsize); } else { j++; if (*p == '\n' || *p == '\r') { i += j; j = 0; } } /* Second pass: create output string and fill it */ u = _PyUnicode_New(i + j); if (!u) return NULL; j = 0; q = u->str; for (p = self->str; p < e; p++) if (*p == '\t') { if (tabsize > 0) { i = tabsize - (j % tabsize); j += i; while (i--) *q++ = ' '; } } else { j++; *q++ = *p; if (*p == '\n' || *p == '\r') j = 0; } return (PyObject*) u;} PyDoc_STRVAR(find__doc__,"S.find(sub [,start [,end]]) -> int\n\\n\Return the lowest index in S where substring sub is found,\n\such that sub is contained within s[start,end]. Optional\n\arguments start and end are interpreted as in slice notation.\n\\n\Return -1 on failure."); static PyObject *unicode_find(PyUnicodeObject *self, PyObject *args){ PyObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; Py_ssize_t result; if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_find_slice( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self), PyUnicode_AS_UNICODE(substring), PyUnicode_GET_SIZE(substring), start, end ); Py_DECREF(substring); return PyInt_FromSsize_t(result);} static PyObject *unicode_getitem(PyUnicodeObject *self, Py_ssize_t index){ if (index < 0 || index >= self->length) { PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } return (PyObject*) PyUnicode_FromUnicode(&self->str[index], 1);} static longunicode_hash(PyUnicodeObject *self){ /* Since Unicode objects compare equal to their ASCII string counterparts, they should use the individual character values as basis for their hash value. This is needed to assure that strings and Unicode objects behave in the same way as dictionary keys. */ register Py_ssize_t len; register Py_UNICODE *p; register long x; if (self->hash != -1) return self->hash; len = PyUnicode_GET_SIZE(self); p = PyUnicode_AS_UNICODE(self); x = *p << 7; while (--len >= 0) x = (1000003*x) ^ *p++; x ^= PyUnicode_GET_SIZE(self); if (x == -1) x = -2; self->hash = x; return x;} PyDoc_STRVAR(index__doc__,"S.index(sub [,start [,end]]) -> int\n\\n\Like S.find() but raise ValueError when the substring is not found."); static PyObject *unicode_index(PyUnicodeObject *self, PyObject *args){ Py_ssize_t result; PyObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_find_slice( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self), PyUnicode_AS_UNICODE(substring), PyUnicode_GET_SIZE(substring), start, end ); Py_DECREF(substring); if (result < 0) { PyErr_SetString(PyExc_ValueError, "substring not found"); return NULL; } return PyInt_FromSsize_t(result);} PyDoc_STRVAR(islower__doc__,"S.islower() -> bool\n\\n\Return True if all cased characters in S are lowercase and there is\n\at least one cased character in S, False otherwise."); static PyObject*unicode_islower(PyUnicodeObject *self){ register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong(Py_UNICODE_ISLOWER(*p)); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISLOWER(ch)) cased = 1; } return PyBool_FromLong(cased);} PyDoc_STRVAR(isupper__doc__,"S.isupper() -> bool\n\\n\Return True if all cased characters in S are uppercase and there is\n\at least one cased character in S, False otherwise."); static PyObject*unicode_isupper(PyUnicodeObject *self){ register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong(Py_UNICODE_ISUPPER(*p) != 0); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch)) return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISUPPER(ch)) cased = 1; } return PyBool_FromLong(cased);} PyDoc_STRVAR(istitle__doc__,"S.istitle() -> bool\n\\n\Return True if S is a titlecased string and there is at least one\n\character in S, i.e. upper- and titlecase characters may only\n\follow uncased characters and lowercase characters only cased ones.\n\Return False otherwise."); static PyObject*unicode_istitle(PyUnicodeObject *self){ register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased, previous_is_cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong((Py_UNICODE_ISTITLE(*p) != 0) || (Py_UNICODE_ISUPPER(*p) != 0)); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; previous_is_cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) { if (previous_is_cased) return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else if (Py_UNICODE_ISLOWER(ch)) { if (!previous_is_cased) return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else previous_is_cased = 0; } return PyBool_FromLong(cased);} PyDoc_STRVAR(isspace__doc__,"S.isspace() -> bool\n\\n\Return True if all characters in S are whitespace\n\and there is at least one character in S, False otherwise."); static PyObject*unicode_isspace(PyUnicodeObject *self){ register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISSPACE(*p)) return PyBool_FromLong(1); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISSPACE(*p)) return PyBool_FromLong(0); } return PyBool_FromLong(1);} PyDoc_STRVAR(isalpha__doc__,"S.isalpha() -> bool\n\\n\Return True if all characters in S are alphabetic\n\and there is at least one character in S, False otherwise."); static PyObject*unicode_isalpha(PyUnicodeObject *self)Lines 5501–6000 of 8067. Previous lines Load more
{ PyObject *str, *sub; int result; /* Coerce the two arguments */ sub = PyUnicode_FromObject(element); if (!sub) { PyErr_SetString(PyExc_TypeError, "'in <string>' requires string as left operand"); return -1; } str = PyUnicode_FromObject(container); if (!str) { Py_DECREF(sub); return -1; } result = stringlib_contains_obj(str, sub); Py_DECREF(str); Py_DECREF(sub); return result; } /* Concat to string or Unicode object giving a new Unicode object. */ PyObject *PyUnicode_Concat(PyObject *left, PyObject *right) { PyUnicodeObject *u = NULL, *v = NULL, *w; /* Coerce the two arguments */ u = (PyUnicodeObject *)PyUnicode_FromObject(left); if (u == NULL) goto onError; v = (PyUnicodeObject *)PyUnicode_FromObject(right); if (v == NULL) goto onError; /* Shortcuts */ if (v == unicode_empty) { Py_DECREF(v); return (PyObject *)u; } if (u == unicode_empty) { Py_DECREF(u); return (PyObject *)v; } /* Concat the two Unicode strings */ w = _PyUnicode_New(u->length + v->length); if (w == NULL) goto onError; Py_UNICODE_COPY(w->str, u->str, u->length); Py_UNICODE_COPY(w->str + u->length, v->str, v->length); Py_DECREF(u); Py_DECREF(v); return (PyObject *)w; onError: Py_XDECREF(u); Py_XDECREF(v); return NULL; } PyDoc_STRVAR(count__doc__, "S.count(sub[, start[, end]]) -> int\n\ \n\ Return the number of non-overlapping occurrences of substring sub in\n\ Unicode string S[start:end]. Optional arguments start and end are\n\ interpreted as in slice notation."); static PyObject * unicode_count(PyUnicodeObject *self, PyObject *args) { PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; PyObject *result; if (!PyArg_ParseTuple(args, "O|O&O&:count", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = (PyUnicodeObject *)PyUnicode_FromObject( (PyObject *)substring); if (substring == NULL) return NULL; FIX_START_END(self); result = PyInt_FromSsize_t( stringlib_count(self->str + start, end - start, substring->str, substring->length) ); Py_DECREF(substring); return result; } PyDoc_STRVAR(encode__doc__, "S.encode([encoding[,errors]]) -> string or unicode\n\ \n\ Encodes S using the codec registered for encoding. encoding defaults\n\ to the default encoding. errors may be given to set a different error\n\ handling scheme. Default is 'strict' meaning that encoding errors raise\n\ a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\ 'xmlcharrefreplace' as well as any other name registered with\n\ codecs.register_error that can handle UnicodeEncodeErrors."); static PyObject * unicode_encode(PyUnicodeObject *self, PyObject *args) { char *encoding = NULL; char *errors = NULL; PyObject *v; if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors)) return NULL; v = PyUnicode_AsEncodedObject((PyObject *)self, encoding, errors); if (v == NULL) goto onError; if (!PyString_Check(v) && !PyUnicode_Check(v)) { PyErr_Format(PyExc_TypeError, "encoder did not return a string/unicode object " "(type=%.400s)", v->ob_type->tp_name); Py_DECREF(v); return NULL; } return v; onError: return NULL; } PyDoc_STRVAR(decode__doc__, "S.decode([encoding[,errors]]) -> string or unicode\n\ \n\ Decodes S using the codec registered for encoding. encoding defaults\n\ to the default encoding. errors may be given to set a different error\n\ handling scheme. Default is 'strict' meaning that encoding errors raise\n\ a UnicodeDecodeError. Other possible values are 'ignore' and 'replace'\n\ as well as any other name registerd with codecs.register_error that is\n\ able to handle UnicodeDecodeErrors."); static PyObject * unicode_decode(PyUnicodeObject *self, PyObject *args) { char *encoding = NULL; char *errors = NULL; PyObject *v; if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors)) return NULL; v = PyUnicode_AsDecodedObject((PyObject *)self, encoding, errors); if (v == NULL) goto onError; if (!PyString_Check(v) && !PyUnicode_Check(v)) { PyErr_Format(PyExc_TypeError, "decoder did not return a string/unicode object " "(type=%.400s)", v->ob_type->tp_name); Py_DECREF(v); return NULL; } return v; onError: return NULL; } PyDoc_STRVAR(expandtabs__doc__, "S.expandtabs([tabsize]) -> unicode\n\ \n\ Return a copy of S where all tab characters are expanded using spaces.\n\ If tabsize is not given, a tab size of 8 characters is assumed."); static PyObject* unicode_expandtabs(PyUnicodeObject *self, PyObject *args) { Py_UNICODE *e; Py_UNICODE *p; Py_UNICODE *q; Py_ssize_t i, j; PyUnicodeObject *u; int tabsize = 8; if (!PyArg_ParseTuple(args, "|i:expandtabs", &tabsize)) return NULL; /* First pass: determine size of output string */ i = j = 0; e = self->str + self->length; for (p = self->str; p < e; p++) if (*p == '\t') { if (tabsize > 0) j += tabsize - (j % tabsize); } else { j++; if (*p == '\n' || *p == '\r') { i += j; j = 0; } } /* Second pass: create output string and fill it */ u = _PyUnicode_New(i + j); if (!u) return NULL; j = 0; q = u->str; for (p = self->str; p < e; p++) if (*p == '\t') { if (tabsize > 0) { i = tabsize - (j % tabsize); j += i; while (i--) *q++ = ' '; } } else { j++; *q++ = *p; if (*p == '\n' || *p == '\r') j = 0; } return (PyObject*) u; } PyDoc_STRVAR(find__doc__, "S.find(sub [,start [,end]]) -> int\n\ \n\ Return the lowest index in S where substring sub is found,\n\ such that sub is contained within s[start,end]. Optional\n\ arguments start and end are interpreted as in slice notation.\n\ \n\ Return -1 on failure."); static PyObject * unicode_find(PyUnicodeObject *self, PyObject *args) { PyObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; Py_ssize_t result; if (!PyArg_ParseTuple(args, "O|O&O&:find", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_find_slice( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self), PyUnicode_AS_UNICODE(substring), PyUnicode_GET_SIZE(substring), start, end ); Py_DECREF(substring); return PyInt_FromSsize_t(result); } static PyObject * unicode_getitem(PyUnicodeObject *self, Py_ssize_t index) { if (index < 0 || index >= self->length) { PyErr_SetString(PyExc_IndexError, "string index out of range"); return NULL; } return (PyObject*) PyUnicode_FromUnicode(&self->str[index], 1); } static long unicode_hash(PyUnicodeObject *self) { /* Since Unicode objects compare equal to their ASCII string counterparts, they should use the individual character values as basis for their hash value. This is needed to assure that strings and Unicode objects behave in the same way as dictionary keys. */ register Py_ssize_t len; register Py_UNICODE *p; register long x; if (self->hash != -1) return self->hash; len = PyUnicode_GET_SIZE(self); p = PyUnicode_AS_UNICODE(self); x = *p << 7; while (--len >= 0) x = (1000003*x) ^ *p++; x ^= PyUnicode_GET_SIZE(self); if (x == -1) x = -2; self->hash = x; return x; } PyDoc_STRVAR(index__doc__, "S.index(sub [,start [,end]]) -> int\n\ \n\ Like S.find() but raise ValueError when the substring is not found."); static PyObject * unicode_index(PyUnicodeObject *self, PyObject *args) { Py_ssize_t result; PyObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; if (!PyArg_ParseTuple(args, "O|O&O&:index", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_find_slice( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self), PyUnicode_AS_UNICODE(substring), PyUnicode_GET_SIZE(substring), start, end ); Py_DECREF(substring); if (result < 0) { PyErr_SetString(PyExc_ValueError, "substring not found"); return NULL; } return PyInt_FromSsize_t(result); } PyDoc_STRVAR(islower__doc__, "S.islower() -> bool\n\ \n\ Return True if all cased characters in S are lowercase and there is\n\ at least one cased character in S, False otherwise."); static PyObject* unicode_islower(PyUnicodeObject *self) { register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong(Py_UNICODE_ISLOWER(*p)); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISLOWER(ch)) cased = 1; } return PyBool_FromLong(cased); } PyDoc_STRVAR(isupper__doc__, "S.isupper() -> bool\n\ \n\ Return True if all cased characters in S are uppercase and there is\n\ at least one cased character in S, False otherwise."); static PyObject* unicode_isupper(PyUnicodeObject *self) { register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong(Py_UNICODE_ISUPPER(*p) != 0); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISLOWER(ch) || Py_UNICODE_ISTITLE(ch)) return PyBool_FromLong(0); else if (!cased && Py_UNICODE_ISUPPER(ch)) cased = 1; } return PyBool_FromLong(cased); } PyDoc_STRVAR(istitle__doc__, "S.istitle() -> bool\n\ \n\ Return True if S is a titlecased string and there is at least one\n\ character in S, i.e. upper- and titlecase characters may only\n\ follow uncased characters and lowercase characters only cased ones.\n\ Return False otherwise."); static PyObject* unicode_istitle(PyUnicodeObject *self) { register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; int cased, previous_is_cased; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1) return PyBool_FromLong((Py_UNICODE_ISTITLE(*p) != 0) || (Py_UNICODE_ISUPPER(*p) != 0)); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); cased = 0; previous_is_cased = 0; for (; p < e; p++) { register const Py_UNICODE ch = *p; if (Py_UNICODE_ISUPPER(ch) || Py_UNICODE_ISTITLE(ch)) { if (previous_is_cased) return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else if (Py_UNICODE_ISLOWER(ch)) { if (!previous_is_cased) return PyBool_FromLong(0); previous_is_cased = 1; cased = 1; } else previous_is_cased = 0; } return PyBool_FromLong(cased); } PyDoc_STRVAR(isspace__doc__, "S.isspace() -> bool\n\ \n\ Return True if all characters in S are whitespace\n\ and there is at least one character in S, False otherwise."); static PyObject* unicode_isspace(PyUnicodeObject *self) { register const Py_UNICODE *p = PyUnicode_AS_UNICODE(self); register const Py_UNICODE *e; /* Shortcut for single character strings */ if (PyUnicode_GET_SIZE(self) == 1 && Py_UNICODE_ISSPACE(*p)) return PyBool_FromLong(1); /* Special case for empty strings */ if (PyUnicode_GET_SIZE(self) == 0) return PyBool_FromLong(0); e = p + PyUnicode_GET_SIZE(self); for (; p < e; p++) { if (!Py_UNICODE_ISSPACE(*p)) return PyBool_FromLong(0); } return PyBool_FromLong(1); } PyDoc_STRVAR(isalpha__doc__, "S.isalpha() -> bool\n\ \n\ Return True if all characters in S are alphabetic\n\ and there is at least one character in S, False otherwise."); static PyObject* unicode_isalpha(PyUnicodeObject *self)