@@ -13021,40 +13021,41 @@ unicode_zfill_impl(PyObject *self, Py_ssize_t width)
13021
13021
return u ;
13022
13022
}
13023
13023
13024
- PyDoc_STRVAR (startswith__doc__ ,
13025
- "S.startswith(prefix[, start[, end]]) -> bool\n\
13026
- \n\
13027
- Return True if S starts with the specified prefix, False otherwise.\n\
13028
- With optional start, test S beginning at that position.\n\
13029
- With optional end, stop comparing S at that position.\n\
13030
- prefix can also be a tuple of strings to try." );
13024
+ /*[clinic input]
13025
+ @text_signature "($self, prefix[, start[, end]], /)"
13026
+ str.startswith as unicode_startswith
13027
+
13028
+ prefix as subobj: object
13029
+ A string or a tuple of strings to try.
13030
+ start: slice_index(accept={int, NoneType}, c_default='0') = None
13031
+ Optional start position. Default: start of the string.
13032
+ end: slice_index(accept={int, NoneType}, c_default='PY_SSIZE_T_MAX') = None
13033
+ Optional stop position. Default: end of the string.
13034
+ /
13035
+
13036
+ Return True if the string starts with the specified prefix, False otherwise.
13037
+ [clinic start generated code]*/
13031
13038
13032
13039
static PyObject *
13033
- unicode_startswith (PyObject * self ,
13034
- PyObject * args )
13040
+ unicode_startswith_impl (PyObject * self , PyObject * subobj , Py_ssize_t start ,
13041
+ Py_ssize_t end )
13042
+ /*[clinic end generated code: output=4bd7cfd0803051d4 input=5f918b5f5f89d856]*/
13035
13043
{
13036
- PyObject * subobj ;
13037
- PyObject * substring ;
13038
- Py_ssize_t start = 0 ;
13039
- Py_ssize_t end = PY_SSIZE_T_MAX ;
13040
- int result ;
13041
-
13042
- if (!asciilib_parse_args_finds ("startswith" , args , & subobj , & start , & end ))
13043
- return NULL ;
13044
13044
if (PyTuple_Check (subobj )) {
13045
13045
Py_ssize_t i ;
13046
13046
for (i = 0 ; i < PyTuple_GET_SIZE (subobj ); i ++ ) {
13047
- substring = PyTuple_GET_ITEM (subobj , i );
13047
+ PyObject * substring = PyTuple_GET_ITEM (subobj , i );
13048
13048
if (!PyUnicode_Check (substring )) {
13049
13049
PyErr_Format (PyExc_TypeError ,
13050
13050
"tuple for startswith must only contain str, "
13051
13051
"not %.100s" ,
13052
13052
Py_TYPE (substring )-> tp_name );
13053
13053
return NULL ;
13054
13054
}
13055
- result = tailmatch (self , substring , start , end , -1 );
13056
- if (result == -1 )
13055
+ int result = tailmatch (self , substring , start , end , -1 );
13056
+ if (result < 0 ) {
13057
13057
return NULL ;
13058
+ }
13058
13059
if (result ) {
13059
13060
Py_RETURN_TRUE ;
13060
13061
}
@@ -13068,47 +13069,41 @@ unicode_startswith(PyObject *self,
13068
13069
"a tuple of str, not %.100s" , Py_TYPE (subobj )-> tp_name );
13069
13070
return NULL ;
13070
13071
}
13071
- result = tailmatch (self , subobj , start , end , -1 );
13072
- if (result == -1 )
13072
+ int result = tailmatch (self , subobj , start , end , -1 );
13073
+ if (result < 0 ) {
13073
13074
return NULL ;
13075
+ }
13074
13076
return PyBool_FromLong (result );
13075
13077
}
13076
13078
13077
13079
13078
- PyDoc_STRVAR (endswith__doc__ ,
13079
- "S.endswith(suffix[, start[, end]]) -> bool\n\
13080
- \n\
13081
- Return True if S ends with the specified suffix, False otherwise.\n\
13082
- With optional start, test S beginning at that position.\n\
13083
- With optional end, stop comparing S at that position.\n\
13084
- suffix can also be a tuple of strings to try." );
13080
+ /*[clinic input]
13081
+ @text_signature "($self, prefix[, start[, end]], /)"
13082
+ str.endswith as unicode_endswith = str.startswith
13083
+
13084
+ Return True if the string ends with the specified prefix, False otherwise.
13085
+ [clinic start generated code]*/
13085
13086
13086
13087
static PyObject *
13087
- unicode_endswith (PyObject * self ,
13088
- PyObject * args )
13088
+ unicode_endswith_impl (PyObject * self , PyObject * subobj , Py_ssize_t start ,
13089
+ Py_ssize_t end )
13090
+ /*[clinic end generated code: output=cce6f8ceb0102ca9 input=82cd5ce9e7623646]*/
13089
13091
{
13090
- PyObject * subobj ;
13091
- PyObject * substring ;
13092
- Py_ssize_t start = 0 ;
13093
- Py_ssize_t end = PY_SSIZE_T_MAX ;
13094
- int result ;
13095
-
13096
- if (!asciilib_parse_args_finds ("endswith" , args , & subobj , & start , & end ))
13097
- return NULL ;
13098
13092
if (PyTuple_Check (subobj )) {
13099
13093
Py_ssize_t i ;
13100
13094
for (i = 0 ; i < PyTuple_GET_SIZE (subobj ); i ++ ) {
13101
- substring = PyTuple_GET_ITEM (subobj , i );
13095
+ PyObject * substring = PyTuple_GET_ITEM (subobj , i );
13102
13096
if (!PyUnicode_Check (substring )) {
13103
13097
PyErr_Format (PyExc_TypeError ,
13104
13098
"tuple for endswith must only contain str, "
13105
13099
"not %.100s" ,
13106
13100
Py_TYPE (substring )-> tp_name );
13107
13101
return NULL ;
13108
13102
}
13109
- result = tailmatch (self , substring , start , end , +1 );
13110
- if (result == -1 )
13103
+ int result = tailmatch (self , substring , start , end , +1 );
13104
+ if (result < 0 ) {
13111
13105
return NULL ;
13106
+ }
13112
13107
if (result ) {
13113
13108
Py_RETURN_TRUE ;
13114
13109
}
@@ -13121,9 +13116,10 @@ unicode_endswith(PyObject *self,
13121
13116
"a tuple of str, not %.100s" , Py_TYPE (subobj )-> tp_name );
13122
13117
return NULL ;
13123
13118
}
13124
- result = tailmatch (self , subobj , start , end , +1 );
13125
- if (result == -1 )
13119
+ int result = tailmatch (self , subobj , start , end , +1 );
13120
+ if (result < 0 ) {
13126
13121
return NULL ;
13122
+ }
13127
13123
return PyBool_FromLong (result );
13128
13124
}
13129
13125
@@ -13576,8 +13572,8 @@ static PyMethodDef unicode_methods[] = {
13576
13572
UNICODE_SWAPCASE_METHODDEF
13577
13573
UNICODE_TRANSLATE_METHODDEF
13578
13574
UNICODE_UPPER_METHODDEF
13579
- { "startswith" , ( PyCFunction ) unicode_startswith , METH_VARARGS , startswith__doc__ },
13580
- { "endswith" , ( PyCFunction ) unicode_endswith , METH_VARARGS , endswith__doc__ },
13575
+ UNICODE_STARTSWITH_METHODDEF
13576
+ UNICODE_ENDSWITH_METHODDEF
13581
13577
UNICODE_REMOVEPREFIX_METHODDEF
13582
13578
UNICODE_REMOVESUFFIX_METHODDEF
13583
13579
UNICODE_ISASCII_METHODDEF
0 commit comments