@@ -333,6 +333,17 @@ PyObject *cstring_rindex(PyObject *self, PyObject *args) {
333333 return PyLong_FromSsize_t (p - CSTRING_VALUE (self ));
334334}
335335
336+ PyDoc_STRVAR (startswith__doc__ , "" );
337+ PyObject * cstring_startswith (PyObject * self , PyObject * args ) {
338+ struct _substr_params params ;
339+ if (!_parse_substr_args (self , args , & params ))
340+ return NULL ;
341+ if (params .end - params .start < params .substr_len )
342+ return PyBool_FromLong (0 );
343+ int cmp = memcmp (params .start , params .substr , params .substr_len );
344+ return PyBool_FromLong (cmp == 0 );
345+ }
346+
336347static PySequenceMethods cstring_as_sequence = {
337348 .sq_length = cstring_len ,
338349 .sq_concat = cstring_concat ,
@@ -352,6 +363,7 @@ static PyMethodDef cstring_methods[] = {
352363 {"index" , cstring_index , METH_VARARGS , index__doc__ },
353364 {"rfind" , cstring_rfind , METH_VARARGS , rfind__doc__ },
354365 {"rindex" , cstring_rindex , METH_VARARGS , rindex__doc__ },
366+ {"startswith" , cstring_startswith , METH_VARARGS , startswith__doc__ },
355367 {0 },
356368};
357369
0 commit comments