Skip to content

Commit 0f5b821

Browse files
cdce8pencukou
andauthored
gh-46236: Document PyUnicode_RSplit, PyUnicode_Partition and PyUnicode_RPartition (#130191)
Co-authored-by: Petr Viktorin <[email protected]>
1 parent 35925e9 commit 0f5b821

File tree

3 files changed

+59
-3
lines changed

3 files changed

+59
-3
lines changed

Doc/c-api/unicode.rst

+41
Original file line numberDiff line numberDiff line change
@@ -1398,6 +1398,20 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
13981398
separator. At most *maxsplit* splits will be done. If negative, no limit is
13991399
set. Separators are not included in the resulting list.
14001400
1401+
On error, return ``NULL`` with an exception set.
1402+
1403+
Equivalent to :py:meth:`str.split`.
1404+
1405+
1406+
.. c:function:: PyObject* PyUnicode_RSplit(PyObject *unicode, PyObject *sep, Py_ssize_t maxsplit)
1407+
1408+
Similar to :c:func:`PyUnicode_Split`, but splitting will be done beginning
1409+
at the end of the string.
1410+
1411+
On error, return ``NULL`` with an exception set.
1412+
1413+
Equivalent to :py:meth:`str.rsplit`.
1414+
14011415
14021416
.. c:function:: PyObject* PyUnicode_Splitlines(PyObject *unicode, int keepends)
14031417
@@ -1406,6 +1420,33 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
14061420
characters are not included in the resulting strings.
14071421
14081422
1423+
.. c:function:: PyObject* PyUnicode_Partition(PyObject *unicode, PyObject *sep)
1424+
1425+
Split a Unicode string at the first occurrence of *sep*, and return
1426+
a 3-tuple containing the part before the separator, the separator itself,
1427+
and the part after the separator. If the separator is not found,
1428+
return a 3-tuple containing the string itself, followed by two empty strings.
1429+
1430+
*sep* must not be empty.
1431+
1432+
On error, return ``NULL`` with an exception set.
1433+
1434+
Equivalent to :py:meth:`str.partition`.
1435+
1436+
1437+
.. c:function:: PyObject* PyUnicode_RPartition(PyObject *unicode, PyObject *sep)
1438+
1439+
Similar to :c:func:`PyUnicode_Partition`, but split a Unicode string at the
1440+
last occurrence of *sep*. If the separator is not found, return a 3-tuple
1441+
containing two empty strings, followed by the string itself.
1442+
1443+
*sep* must not be empty.
1444+
1445+
On error, return ``NULL`` with an exception set.
1446+
1447+
Equivalent to :py:meth:`str.rpartition`.
1448+
1449+
14091450
.. c:function:: PyObject* PyUnicode_Join(PyObject *separator, PyObject *seq)
14101451
14111452
Join a sequence of strings using the given *separator* and return the resulting

Doc/data/refcounts.dat

+16-3
Original file line numberDiff line numberDiff line change
@@ -2655,13 +2655,26 @@ PyUnicode_Concat:PyObject*::+1:
26552655
PyUnicode_Concat:PyObject*:left:0:
26562656
PyUnicode_Concat:PyObject*:right:0:
26572657

2658+
PyUnicode_Partition:PyObject*::+1:
2659+
PyUnicode_Partition:PyObject*:unicode:0:
2660+
PyUnicode_Partition:PyObject*:sep:0:
2661+
2662+
PyUnicode_RPartition:PyObject*::+1:
2663+
PyUnicode_RPartition:PyObject*:unicode:0:
2664+
PyUnicode_RPartition:PyObject*:sep:0:
2665+
2666+
PyUnicode_RSplit:PyObject*::+1:
2667+
PyUnicode_RSplit:PyObject*:unicode:0:
2668+
PyUnicode_RSplit:PyObject*:sep:0:
2669+
PyUnicode_RSplit:Py_ssize_t:maxsplit::
2670+
26582671
PyUnicode_Split:PyObject*::+1:
2659-
PyUnicode_Split:PyObject*:left:0:
2660-
PyUnicode_Split:PyObject*:right:0:
2672+
PyUnicode_Split:PyObject*:unicode:0:
2673+
PyUnicode_Split:PyObject*:sep:0:
26612674
PyUnicode_Split:Py_ssize_t:maxsplit::
26622675

26632676
PyUnicode_Splitlines:PyObject*::+1:
2664-
PyUnicode_Splitlines:PyObject*:s:0:
2677+
PyUnicode_Splitlines:PyObject*:unicode:0:
26652678
PyUnicode_Splitlines:int:keepend::
26662679

26672680
PyUnicode_Translate:PyObject*::+1:
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
C API: Document :c:func:`PyUnicode_RSplit`, :c:func:`PyUnicode_Partition` and
2+
:c:func:`PyUnicode_RPartition`.

0 commit comments

Comments
 (0)