From: Victor Stinner Date: Tue, 10 Aug 2010 16:37:20 +0000 (+0000) Subject: Issue #9425: create Py_UNICODE_strrchr() function X-Git-Tag: v3.2a2~378 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=331ea92ade37e5dcf14c44df59e5eda2136b1a8f;p=python Issue #9425: create Py_UNICODE_strrchr() function --- diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 6448cdab80..7f5e8fdacf 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1622,6 +1622,10 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr( const Py_UNICODE *s, Py_UNICODE c ); +PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr( + const Py_UNICODE *s, Py_UNICODE c + ); + #ifdef __cplusplus } #endif diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index f2d666de12..478f9a976e 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -9965,6 +9965,19 @@ Py_UNICODE_strchr(const Py_UNICODE *s, Py_UNICODE c) return NULL; } +Py_UNICODE* +Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c) +{ + const Py_UNICODE *p; + p = s + Py_UNICODE_strlen(s); + while (p != s) { + p--; + if (*p == c) + return (Py_UNICODE*)p; + } + return NULL; +} + #ifdef __cplusplus }