@@ -321,6 +321,22 @@ PyObject *cstring_rfind(PyObject *self, PyObject *args) {
321321 return PyLong_FromSsize_t (p - CSTRING_VALUE (self ));
322322}
323323
324+ PyDoc_STRVAR (rindex__doc__ , "" );
325+ PyObject * cstring_rindex (PyObject * self , PyObject * args ) {
326+ struct _substr_params params ;
327+
328+ if (!_parse_substr_args (self , args , & params ))
329+ return NULL ;
330+
331+ const char * p = _substr_params_rstr (& params );
332+ if (!p ) {
333+ PyErr_SetString (PyExc_ValueError , "substring not found" );
334+ return NULL ;
335+ }
336+
337+ return PyLong_FromSsize_t (p - CSTRING_VALUE (self ));
338+ }
339+
324340static PySequenceMethods cstring_as_sequence = {
325341 .sq_length = cstring_len ,
326342 .sq_concat = cstring_concat ,
@@ -339,6 +355,7 @@ static PyMethodDef cstring_methods[] = {
339355 {"find" , cstring_find , METH_VARARGS , find__doc__ },
340356 {"index" , cstring_index , METH_VARARGS , index__doc__ },
341357 {"rfind" , cstring_rfind , METH_VARARGS , rfind__doc__ },
358+ {"rindex" , cstring_rindex , METH_VARARGS , rindex__doc__ },
342359 {0 },
343360};
344361
0 commit comments