Skip to content

Commit fa413de

Browse files
committed
Implement C API function PyUnicode_Tailmatch.
1 parent 264d752 commit fa413de

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

graalpython/com.oracle.graal.python.cext/src/unicodeobject.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,3 +491,8 @@ PyObject * PyUnicode_Decode(const char *s, Py_ssize_t size, const char *encoding
491491
PyObject * PyUnicode_DecodeASCII(const char *s, Py_ssize_t size, const char *errors) {
492492
return PyUnicode_Decode(s, size, "ascii", errors);
493493
}
494+
495+
UPCALL_ID(PyUnicode_Tailmatch);
496+
Py_ssize_t PyUnicode_Tailmatch(PyObject *str, PyObject *substr, Py_ssize_t start, Py_ssize_t end, int direction) {
497+
return UPCALL_CEXT_L(_jls_PyUnicode_Tailmatch, native_to_java(str), native_to_java(substr), start, end, direction);
498+
}

graalpython/lib-graalpython/python_cext.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,13 @@ def PyUnicode_AsUnicodeEscapeString(string):
770770
return _codecs_module.unicode_escape_encode(string)[0]
771771

772772

773+
@may_raise(-1)
774+
def PyUnicode_Tailmatch(s, substr, start, end, direction):
775+
if direction > 0:
776+
return 1 if s[start:end].endswith(substr) else 0
777+
return 1 if s[start:end].startswith(substr) else 0
778+
779+
773780
##################### CAPSULE
774781

775782

0 commit comments

Comments
 (0)