Skip to content

Commit ef6a03c

Browse files
committed
Implement C API function PyUnicode_Replace.
1 parent f5b96f4 commit ef6a03c

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-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
@@ -512,3 +512,8 @@ UPCALL_ID(PyUnicode_AsEncodedString);
512512
PyObject * PyUnicode_AsEncodedString(PyObject *unicode, const char *encoding, const char *errors) {
513513
return UPCALL_CEXT_O(_jls_PyUnicode_AsEncodedString, native_to_java(unicode), polyglot_from_string(encoding, SRC_CS), polyglot_from_string(errors, SRC_CS));
514514
}
515+
516+
UPCALL_ID(PyUnicode_Replace);
517+
PyObject * PyUnicode_Replace(PyObject *str, PyObject *substr, PyObject *replstr, Py_ssize_t maxcount) {
518+
return UPCALL_CEXT_O(_jls_PyUnicode_Replace, native_to_java(str), native_to_java(substr), native_to_java(replstr), maxcount);
519+
}

graalpython/lib-graalpython/python_cext.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -789,6 +789,11 @@ def PyUnicode_AsEncodedString(s, encoding, errors):
789789
return s.encode(encoding, errors)
790790

791791

792+
@may_raise
793+
def PyUnicode_Replace(s, substr, replstr, count):
794+
return s.replace(substr, replstr, count)
795+
796+
792797
##################### CAPSULE
793798

794799

0 commit comments

Comments
 (0)