@@ -344,6 +344,17 @@ PyObject *cstring_startswith(PyObject *self, PyObject *args) {
344344 return PyBool_FromLong (cmp == 0 );
345345}
346346
347+ PyDoc_STRVAR (endswith__doc__ , "" );
348+ PyObject * cstring_endswith (PyObject * self , PyObject * args ) {
349+ struct _substr_params params ;
350+ if (!_parse_substr_args (self , args , & params ))
351+ return NULL ;
352+ if (params .end - params .start < params .substr_len )
353+ return PyBool_FromLong (0 );
354+ int cmp = memcmp (params .end - params .substr_len , params .substr , params .substr_len );
355+ return PyBool_FromLong (cmp == 0 );
356+ }
357+
347358static PySequenceMethods cstring_as_sequence = {
348359 .sq_length = cstring_len ,
349360 .sq_concat = cstring_concat ,
@@ -364,6 +375,7 @@ static PyMethodDef cstring_methods[] = {
364375 {"rfind" , cstring_rfind , METH_VARARGS , rfind__doc__ },
365376 {"rindex" , cstring_rindex , METH_VARARGS , rindex__doc__ },
366377 {"startswith" , cstring_startswith , METH_VARARGS , startswith__doc__ },
378+ {"endswith" , cstring_endswith , METH_VARARGS , endswith__doc__ },
367379 {0 },
368380};
369381
0 commit comments