if (!substring) return NULL; result = stringlib_rfind_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);} PyDoc_STRVAR(rindex__doc__,"S.rindex(sub [,start [,end]]) -> int\n\\n\Like S.rfind() but raise ValueError when the substring is not found."); static PyObject *unicode_rindex(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&:rindex", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_rfind_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(rjust__doc__,"S.rjust(width[, fillchar]) -> unicode\n\\n\Return S right justified in a Unicode string of length width. Padding is\n\done using the specified fill character (default is a space)."); static PyObject *unicode_rjust(PyUnicodeObject *self, PyObject *args){ Py_ssize_t width; Py_UNICODE fillchar = ' '; if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar)) return NULL; if (self->length >= width && PyUnicode_CheckExact(self)) { Py_INCREF(self); return (PyObject*) self; } return (PyObject*) pad(self, width - self->length, 0, fillchar);} static PyObject*unicode_slice(PyUnicodeObject *self, Py_ssize_t start, Py_ssize_t end){ /* standard clamping */ if (start < 0) start = 0; if (end < 0) end = 0; if (end > self->length) end = self->length; if (start == 0 && end == self->length && PyUnicode_CheckExact(self)) { /* full slice, return original string */ Py_INCREF(self); return (PyObject*) self; } if (start > end) start = end; /* copy slice */ return (PyObject*) PyUnicode_FromUnicode(self->str + start, end - start);} PyObject *PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit){ PyObject *result; s = PyUnicode_FromObject(s); if (s == NULL) return NULL; if (sep != NULL) { sep = PyUnicode_FromObject(sep); if (sep == NULL) { Py_DECREF(s); return NULL; } } result = split((PyUnicodeObject *)s, (PyUnicodeObject *)sep, maxsplit); Py_DECREF(s); Py_XDECREF(sep); return result;} PyDoc_STRVAR(split__doc__,"S.split([sep [,maxsplit]]) -> list of strings\n\\n\Return a list of the words in S, using sep as the\n\delimiter string. If maxsplit is given, at most maxsplit\n\splits are done. If sep is not specified or is None,\n\any whitespace string is a separator."); static PyObject*unicode_split(PyUnicodeObject *self, PyObject *args){ PyObject *substring = Py_None; Py_ssize_t maxcount = -1; if (!PyArg_ParseTuple(args, "|On:split", &substring, &maxcount)) return NULL; if (substring == Py_None) return split(self, NULL, maxcount); else if (PyUnicode_Check(substring)) return split(self, (PyUnicodeObject *)substring, maxcount); else return PyUnicode_Split((PyObject *)self, substring, maxcount);} PyObject *PyUnicode_Partition(PyObject *str_in, PyObject *sep_in){ PyObject* str_obj; PyObject* sep_obj; PyObject* out; str_obj = PyUnicode_FromObject(str_in); if (!str_obj) return NULL; sep_obj = PyUnicode_FromObject(sep_in); if (!sep_obj) { Py_DECREF(str_obj); return NULL; } out = stringlib_partition( str_obj, PyUnicode_AS_UNICODE(str_obj), PyUnicode_GET_SIZE(str_obj), sep_obj, PyUnicode_AS_UNICODE(sep_obj), PyUnicode_GET_SIZE(sep_obj) ); Py_DECREF(sep_obj); Py_DECREF(str_obj); return out;} PyObject *PyUnicode_RPartition(PyObject *str_in, PyObject *sep_in){ PyObject* str_obj; PyObject* sep_obj; PyObject* out; str_obj = PyUnicode_FromObject(str_in); if (!str_obj) return NULL; sep_obj = PyUnicode_FromObject(sep_in); if (!sep_obj) { Py_DECREF(str_obj); return NULL; } out = stringlib_rpartition( str_obj, PyUnicode_AS_UNICODE(str_obj), PyUnicode_GET_SIZE(str_obj), sep_obj, PyUnicode_AS_UNICODE(sep_obj), PyUnicode_GET_SIZE(sep_obj) ); Py_DECREF(sep_obj); Py_DECREF(str_obj); return out;} PyDoc_STRVAR(partition__doc__,"S.partition(sep) -> (head, sep, tail)\n\\n\Searches for the separator sep in S, and returns the part before it,\n\the separator itself, and the part after it. If the separator is not\n\found, returns S and two empty strings."); static PyObject*unicode_partition(PyUnicodeObject *self, PyObject *separator){ return PyUnicode_Partition((PyObject *)self, separator);} PyDoc_STRVAR(rpartition__doc__,"S.rpartition(sep) -> (tail, sep, head)\n\\n\Searches for the separator sep in S, starting at the end of S, and returns\n\the part before it, the separator itself, and the part after it. If the\n\separator is not found, returns two empty strings and S."); static PyObject*unicode_rpartition(PyUnicodeObject *self, PyObject *separator){ return PyUnicode_RPartition((PyObject *)self, separator);} PyObject *PyUnicode_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit){ PyObject *result; s = PyUnicode_FromObject(s); if (s == NULL) return NULL; if (sep != NULL) { sep = PyUnicode_FromObject(sep); if (sep == NULL) { Py_DECREF(s); return NULL; } } result = rsplit((PyUnicodeObject *)s, (PyUnicodeObject *)sep, maxsplit); Py_DECREF(s); Py_XDECREF(sep); return result;} PyDoc_STRVAR(rsplit__doc__,"S.rsplit([sep [,maxsplit]]) -> list of strings\n\\n\Return a list of the words in S, using sep as the\n\delimiter string, starting at the end of the string and\n\working to the front. If maxsplit is given, at most maxsplit\n\splits are done. If sep is not specified, any whitespace string\n\is a separator."); static PyObject*unicode_rsplit(PyUnicodeObject *self, PyObject *args){ PyObject *substring = Py_None; Py_ssize_t maxcount = -1; if (!PyArg_ParseTuple(args, "|On:rsplit", &substring, &maxcount)) return NULL; if (substring == Py_None) return rsplit(self, NULL, maxcount); else if (PyUnicode_Check(substring)) return rsplit(self, (PyUnicodeObject *)substring, maxcount); else return PyUnicode_RSplit((PyObject *)self, substring, maxcount);} PyDoc_STRVAR(splitlines__doc__,"S.splitlines([keepends]]) -> list of strings\n\\n\Return a list of the lines in S, breaking at line boundaries.\n\Line breaks are not included in the resulting list unless keepends\n\is given and true."); static PyObject*unicode_splitlines(PyUnicodeObject *self, PyObject *args){ int keepends = 0; if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) return NULL; return PyUnicode_Splitlines((PyObject *)self, keepends);} staticPyObject *unicode_str(PyUnicodeObject *self){ return PyUnicode_AsEncodedString((PyObject *)self, NULL, NULL);} PyDoc_STRVAR(swapcase__doc__,"S.swapcase() -> unicode\n\\n\Return a copy of S with uppercase characters converted to lowercase\n\and vice versa."); static PyObject*unicode_swapcase(PyUnicodeObject *self){ return fixup(self, fixswapcase);} PyDoc_STRVAR(translate__doc__,"S.translate(table) -> unicode\n\\n\Return a copy of the string S, where all characters have been mapped\n\through the given translation table, which must be a mapping of\n\Unicode ordinals to Unicode ordinals, Unicode strings or None.\n\Unmapped characters are left untouched. Characters mapped to None\n\are deleted."); static PyObject*unicode_translate(PyUnicodeObject *self, PyObject *table){ return PyUnicode_TranslateCharmap(self->str, self->length, table, "ignore");} PyDoc_STRVAR(upper__doc__,"S.upper() -> unicode\n\\n\Return a copy of S converted to uppercase."); static PyObject*unicode_upper(PyUnicodeObject *self){ return fixup(self, fixupper);} PyDoc_STRVAR(zfill__doc__,"S.zfill(width) -> unicode\n\\n\Pad a numeric string x with zeros on the left, to fill a field\n\of the specified width. The string x is never truncated."); static PyObject *unicode_zfill(PyUnicodeObject *self, PyObject *args){ Py_ssize_t fill; PyUnicodeObject *u; Py_ssize_t width; if (!PyArg_ParseTuple(args, "n:zfill", &width)) return NULL; if (self->length >= width) { if (PyUnicode_CheckExact(self)) { Py_INCREF(self); return (PyObject*) self; } else return PyUnicode_FromUnicode( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self) ); } fill = width - self->length; u = pad(self, fill, 0, '0'); if (u == NULL) return NULL; if (u->str[fill] == '+' || u->str[fill] == '-') { /* move sign to beginning of string */ u->str[0] = u->str[fill]; u->str[fill] = '0'; } return (PyObject*) u;} #if 0static PyObject*unicode_freelistsize(PyUnicodeObject *self){ return PyInt_FromLong(unicode_freelist_size);}#endif PyDoc_STRVAR(startswith__doc__,"S.startswith(prefix[, start[, end]]) -> bool\n\\n\Return True if S starts with the specified prefix, False otherwise.\n\With optional start, test S beginning at that position.\n\With optional end, stop comparing S at that position.\n\prefix can also be a tuple of strings to try."); static PyObject *unicode_startswith(PyUnicodeObject *self, PyObject *args){ PyObject *subobj; PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; int result; if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { substring = (PyUnicodeObject *)PyUnicode_FromObject( PyTuple_GET_ITEM(subobj, i)); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, -1); Py_DECREF(substring); if (result) { Py_RETURN_TRUE; } } /* nothing matched */ Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, -1); Py_DECREF(substring); return PyBool_FromLong(result);} PyDoc_STRVAR(endswith__doc__,"S.endswith(suffix[, start[, end]]) -> bool\n\\n\Return True if S ends with the specified suffix, False otherwise.\n\With optional start, test S beginning at that position.\n\With optional end, stop comparing S at that position.\n\suffix can also be a tuple of strings to try."); static PyObject *unicode_endswith(PyUnicodeObject *self, PyObject *args){ PyObject *subobj; PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; int result; if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { substring = (PyUnicodeObject *)PyUnicode_FromObject( PyTuple_GET_ITEM(subobj, i)); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, +1); Py_DECREF(substring); if (result) { Py_RETURN_TRUE; } } Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, +1); Py_DECREF(substring); return PyBool_FromLong(result);} static PyObject *unicode_getnewargs(PyUnicodeObject *v){ return Py_BuildValue("(u#)", v->str, v->length);} static PyMethodDef unicode_methods[] = { /* Order is according to common usage: often used methods should appear first, since lookup is done sequentially. */ {"encode", (PyCFunction) unicode_encode, METH_VARARGS, encode__doc__}, {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__}, {"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__}, {"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS, rsplit__doc__},Lines 6501–7000 of 8067. Previous lines Load more
if (!substring) return NULL; result = stringlib_rfind_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); } PyDoc_STRVAR(rindex__doc__, "S.rindex(sub [,start [,end]]) -> int\n\ \n\ Like S.rfind() but raise ValueError when the substring is not found."); static PyObject * unicode_rindex(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&:rindex", &substring, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; substring = PyUnicode_FromObject(substring); if (!substring) return NULL; result = stringlib_rfind_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(rjust__doc__, "S.rjust(width[, fillchar]) -> unicode\n\ \n\ Return S right justified in a Unicode string of length width. Padding is\n\ done using the specified fill character (default is a space)."); static PyObject * unicode_rjust(PyUnicodeObject *self, PyObject *args) { Py_ssize_t width; Py_UNICODE fillchar = ' '; if (!PyArg_ParseTuple(args, "n|O&:rjust", &width, convert_uc, &fillchar)) return NULL; if (self->length >= width && PyUnicode_CheckExact(self)) { Py_INCREF(self); return (PyObject*) self; } return (PyObject*) pad(self, width - self->length, 0, fillchar); } static PyObject* unicode_slice(PyUnicodeObject *self, Py_ssize_t start, Py_ssize_t end) { /* standard clamping */ if (start < 0) start = 0; if (end < 0) end = 0; if (end > self->length) end = self->length; if (start == 0 && end == self->length && PyUnicode_CheckExact(self)) { /* full slice, return original string */ Py_INCREF(self); return (PyObject*) self; } if (start > end) start = end; /* copy slice */ return (PyObject*) PyUnicode_FromUnicode(self->str + start, end - start); } PyObject *PyUnicode_Split(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) { PyObject *result; s = PyUnicode_FromObject(s); if (s == NULL) return NULL; if (sep != NULL) { sep = PyUnicode_FromObject(sep); if (sep == NULL) { Py_DECREF(s); return NULL; } } result = split((PyUnicodeObject *)s, (PyUnicodeObject *)sep, maxsplit); Py_DECREF(s); Py_XDECREF(sep); return result; } PyDoc_STRVAR(split__doc__, "S.split([sep [,maxsplit]]) -> list of strings\n\ \n\ Return a list of the words in S, using sep as the\n\ delimiter string. If maxsplit is given, at most maxsplit\n\ splits are done. If sep is not specified or is None,\n\ any whitespace string is a separator."); static PyObject* unicode_split(PyUnicodeObject *self, PyObject *args) { PyObject *substring = Py_None; Py_ssize_t maxcount = -1; if (!PyArg_ParseTuple(args, "|On:split", &substring, &maxcount)) return NULL; if (substring == Py_None) return split(self, NULL, maxcount); else if (PyUnicode_Check(substring)) return split(self, (PyUnicodeObject *)substring, maxcount); else return PyUnicode_Split((PyObject *)self, substring, maxcount); } PyObject * PyUnicode_Partition(PyObject *str_in, PyObject *sep_in) { PyObject* str_obj; PyObject* sep_obj; PyObject* out; str_obj = PyUnicode_FromObject(str_in); if (!str_obj) return NULL; sep_obj = PyUnicode_FromObject(sep_in); if (!sep_obj) { Py_DECREF(str_obj); return NULL; } out = stringlib_partition( str_obj, PyUnicode_AS_UNICODE(str_obj), PyUnicode_GET_SIZE(str_obj), sep_obj, PyUnicode_AS_UNICODE(sep_obj), PyUnicode_GET_SIZE(sep_obj) ); Py_DECREF(sep_obj); Py_DECREF(str_obj); return out; } PyObject * PyUnicode_RPartition(PyObject *str_in, PyObject *sep_in) { PyObject* str_obj; PyObject* sep_obj; PyObject* out; str_obj = PyUnicode_FromObject(str_in); if (!str_obj) return NULL; sep_obj = PyUnicode_FromObject(sep_in); if (!sep_obj) { Py_DECREF(str_obj); return NULL; } out = stringlib_rpartition( str_obj, PyUnicode_AS_UNICODE(str_obj), PyUnicode_GET_SIZE(str_obj), sep_obj, PyUnicode_AS_UNICODE(sep_obj), PyUnicode_GET_SIZE(sep_obj) ); Py_DECREF(sep_obj); Py_DECREF(str_obj); return out; } PyDoc_STRVAR(partition__doc__, "S.partition(sep) -> (head, sep, tail)\n\ \n\ Searches for the separator sep in S, and returns the part before it,\n\ the separator itself, and the part after it. If the separator is not\n\ found, returns S and two empty strings."); static PyObject* unicode_partition(PyUnicodeObject *self, PyObject *separator) { return PyUnicode_Partition((PyObject *)self, separator); } PyDoc_STRVAR(rpartition__doc__, "S.rpartition(sep) -> (tail, sep, head)\n\ \n\ Searches for the separator sep in S, starting at the end of S, and returns\n\ the part before it, the separator itself, and the part after it. If the\n\ separator is not found, returns two empty strings and S."); static PyObject* unicode_rpartition(PyUnicodeObject *self, PyObject *separator) { return PyUnicode_RPartition((PyObject *)self, separator); } PyObject *PyUnicode_RSplit(PyObject *s, PyObject *sep, Py_ssize_t maxsplit) { PyObject *result; s = PyUnicode_FromObject(s); if (s == NULL) return NULL; if (sep != NULL) { sep = PyUnicode_FromObject(sep); if (sep == NULL) { Py_DECREF(s); return NULL; } } result = rsplit((PyUnicodeObject *)s, (PyUnicodeObject *)sep, maxsplit); Py_DECREF(s); Py_XDECREF(sep); return result; } PyDoc_STRVAR(rsplit__doc__, "S.rsplit([sep [,maxsplit]]) -> list of strings\n\ \n\ Return a list of the words in S, using sep as the\n\ delimiter string, starting at the end of the string and\n\ working to the front. If maxsplit is given, at most maxsplit\n\ splits are done. If sep is not specified, any whitespace string\n\ is a separator."); static PyObject* unicode_rsplit(PyUnicodeObject *self, PyObject *args) { PyObject *substring = Py_None; Py_ssize_t maxcount = -1; if (!PyArg_ParseTuple(args, "|On:rsplit", &substring, &maxcount)) return NULL; if (substring == Py_None) return rsplit(self, NULL, maxcount); else if (PyUnicode_Check(substring)) return rsplit(self, (PyUnicodeObject *)substring, maxcount); else return PyUnicode_RSplit((PyObject *)self, substring, maxcount); } PyDoc_STRVAR(splitlines__doc__, "S.splitlines([keepends]]) -> list of strings\n\ \n\ Return a list of the lines in S, breaking at line boundaries.\n\ Line breaks are not included in the resulting list unless keepends\n\ is given and true."); static PyObject* unicode_splitlines(PyUnicodeObject *self, PyObject *args) { int keepends = 0; if (!PyArg_ParseTuple(args, "|i:splitlines", &keepends)) return NULL; return PyUnicode_Splitlines((PyObject *)self, keepends); } static PyObject *unicode_str(PyUnicodeObject *self) { return PyUnicode_AsEncodedString((PyObject *)self, NULL, NULL); } PyDoc_STRVAR(swapcase__doc__, "S.swapcase() -> unicode\n\ \n\ Return a copy of S with uppercase characters converted to lowercase\n\ and vice versa."); static PyObject* unicode_swapcase(PyUnicodeObject *self) { return fixup(self, fixswapcase); } PyDoc_STRVAR(translate__doc__, "S.translate(table) -> unicode\n\ \n\ Return a copy of the string S, where all characters have been mapped\n\ through the given translation table, which must be a mapping of\n\ Unicode ordinals to Unicode ordinals, Unicode strings or None.\n\ Unmapped characters are left untouched. Characters mapped to None\n\ are deleted."); static PyObject* unicode_translate(PyUnicodeObject *self, PyObject *table) { return PyUnicode_TranslateCharmap(self->str, self->length, table, "ignore"); } PyDoc_STRVAR(upper__doc__, "S.upper() -> unicode\n\ \n\ Return a copy of S converted to uppercase."); static PyObject* unicode_upper(PyUnicodeObject *self) { return fixup(self, fixupper); } PyDoc_STRVAR(zfill__doc__, "S.zfill(width) -> unicode\n\ \n\ Pad a numeric string x with zeros on the left, to fill a field\n\ of the specified width. The string x is never truncated."); static PyObject * unicode_zfill(PyUnicodeObject *self, PyObject *args) { Py_ssize_t fill; PyUnicodeObject *u; Py_ssize_t width; if (!PyArg_ParseTuple(args, "n:zfill", &width)) return NULL; if (self->length >= width) { if (PyUnicode_CheckExact(self)) { Py_INCREF(self); return (PyObject*) self; } else return PyUnicode_FromUnicode( PyUnicode_AS_UNICODE(self), PyUnicode_GET_SIZE(self) ); } fill = width - self->length; u = pad(self, fill, 0, '0'); if (u == NULL) return NULL; if (u->str[fill] == '+' || u->str[fill] == '-') { /* move sign to beginning of string */ u->str[0] = u->str[fill]; u->str[fill] = '0'; } return (PyObject*) u; } #if 0 static PyObject* unicode_freelistsize(PyUnicodeObject *self) { return PyInt_FromLong(unicode_freelist_size); } #endif PyDoc_STRVAR(startswith__doc__, "S.startswith(prefix[, start[, end]]) -> bool\n\ \n\ Return True if S starts with the specified prefix, False otherwise.\n\ With optional start, test S beginning at that position.\n\ With optional end, stop comparing S at that position.\n\ prefix can also be a tuple of strings to try."); static PyObject * unicode_startswith(PyUnicodeObject *self, PyObject *args) { PyObject *subobj; PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; int result; if (!PyArg_ParseTuple(args, "O|O&O&:startswith", &subobj, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { substring = (PyUnicodeObject *)PyUnicode_FromObject( PyTuple_GET_ITEM(subobj, i)); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, -1); Py_DECREF(substring); if (result) { Py_RETURN_TRUE; } } /* nothing matched */ Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, -1); Py_DECREF(substring); return PyBool_FromLong(result); } PyDoc_STRVAR(endswith__doc__, "S.endswith(suffix[, start[, end]]) -> bool\n\ \n\ Return True if S ends with the specified suffix, False otherwise.\n\ With optional start, test S beginning at that position.\n\ With optional end, stop comparing S at that position.\n\ suffix can also be a tuple of strings to try."); static PyObject * unicode_endswith(PyUnicodeObject *self, PyObject *args) { PyObject *subobj; PyUnicodeObject *substring; Py_ssize_t start = 0; Py_ssize_t end = PY_SSIZE_T_MAX; int result; if (!PyArg_ParseTuple(args, "O|O&O&:endswith", &subobj, _PyEval_SliceIndex, &start, _PyEval_SliceIndex, &end)) return NULL; if (PyTuple_Check(subobj)) { Py_ssize_t i; for (i = 0; i < PyTuple_GET_SIZE(subobj); i++) { substring = (PyUnicodeObject *)PyUnicode_FromObject( PyTuple_GET_ITEM(subobj, i)); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, +1); Py_DECREF(substring); if (result) { Py_RETURN_TRUE; } } Py_RETURN_FALSE; } substring = (PyUnicodeObject *)PyUnicode_FromObject(subobj); if (substring == NULL) return NULL; result = tailmatch(self, substring, start, end, +1); Py_DECREF(substring); return PyBool_FromLong(result); } static PyObject * unicode_getnewargs(PyUnicodeObject *v) { return Py_BuildValue("(u#)", v->str, v->length); } static PyMethodDef unicode_methods[] = { /* Order is according to common usage: often used methods should appear first, since lookup is done sequentially. */ {"encode", (PyCFunction) unicode_encode, METH_VARARGS, encode__doc__}, {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__}, {"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__}, {"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS, rsplit__doc__},