Skip to content

Commit 331ea92

Browse files
author
Victor Stinner
committed
Issue #9425: create Py_UNICODE_strrchr() function
1 parent e1dd174 commit 331ea92

2 files changed

Lines changed: 17 additions & 0 deletions

File tree

‎Include/unicodeobject.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1622,6 +1622,10 @@ PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strchr(
16221622
const Py_UNICODE *s, Py_UNICODE c
16231623
);
16241624

1625+
PyAPI_FUNC(Py_UNICODE*) Py_UNICODE_strrchr(
1626+
const Py_UNICODE *s, Py_UNICODE c
1627+
);
1628+
16251629
#ifdef __cplusplus
16261630
}
16271631
#endif

‎Objects/unicodeobject.c‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9965,6 +9965,19 @@ Py_UNICODE_strchr(const Py_UNICODE *s, Py_UNICODE c)
99659965
return NULL;
99669966
}
99679967

9968+
Py_UNICODE*
9969+
Py_UNICODE_strrchr(const Py_UNICODE *s, Py_UNICODE c)
9970+
{
9971+
const Py_UNICODE *p;
9972+
p = s + Py_UNICODE_strlen(s);
9973+
while (p != s) {
9974+
p--;
9975+
if (*p == c)
9976+
return (Py_UNICODE*)p;
9977+
}
9978+
return NULL;
9979+
}
9980+
99689981

99699982
#ifdef __cplusplus
99709983
}

0 commit comments

Comments
 (0)