Skip to content

gh-73123: Add a keepempty argument to string, bytes and bytearray split methods #26222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 28 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
ac9270f
Initial conversion of abarry's patch file.
MarkCBell May 17, 2021
0912ede
Switched logic to use keepempty.
MarkCBell May 17, 2021
f4a101f
Adding in string tests.
MarkCBell May 17, 2021
ade9688
Switched back to PyUnicode_Split taking an int flag.
MarkCBell May 17, 2021
aa4ee9a
Whitespace.
MarkCBell May 17, 2021
76ec07d
Regenerated.
MarkCBell May 17, 2021
38810e5
Added empty string checks to split methods.
MarkCBell May 17, 2021
e0468c1
Cant autobail when string has length 0.
MarkCBell May 17, 2021
5c84475
Better small test.
MarkCBell May 18, 2021
ae0f1ee
More tests.
MarkCBell May 18, 2021
b781cfc
Better small case.
MarkCBell May 18, 2021
6e09909
New splitting algorithms that are compatible with maxsplit.
MarkCBell May 18, 2021
c5ccbeb
Converted rstrip_char and readded optimisations.
MarkCBell May 18, 2021
9e1cd1e
Rewritten split to use new algorithm.
MarkCBell May 18, 2021
4463211
Completed conversion of rsplit.
MarkCBell May 18, 2021
4501026
Fixed use of ! PyObject_IsTrue.
MarkCBell May 18, 2021
d2d6fe6
Fixed bug in FASTSEARCH bounds.
MarkCBell May 18, 2021
cbbf25d
Added keepempty argument to UserString.
MarkCBell May 18, 2021
720a6a6
📜🤖 Added by blurb_it.
blurb-it[bot] May 18, 2021
1959126
News needs to use .
MarkCBell May 19, 2021
cea8af9
Added tests to check interaction with maxsplit.
MarkCBell May 19, 2021
21a2fc4
Also documentation change to PyUnicode_Split and RSplit.
MarkCBell May 19, 2021
e7828fc
Created separate PyUnicode_SplitWithKeepempty and PyUnicode_RSplitWit…
MarkCBell May 19, 2021
dc610bb
Added PyUnicode_SplitWithKeepempty to API/ABI.
MarkCBell May 19, 2021
f95b254
Realised C API interfaces to new keepempty flag is not mandatory.
MarkCBell May 19, 2021
41cbb49
Merge branch 'main' into split-keepempty
MarkCBell Aug 8, 2021
1b1e755
Merge branch 'main' into split-keepempty
MarkCBell Oct 6, 2021
b48ee71
Merge branch 'main' into split-keepempty
MarkCBell Dec 30, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added empty string checks to split methods.
  • Loading branch information
MarkCBell committed May 17, 2021
commit 38810e583fd224c1dae1d0873eb4c827f842aa0b
54 changes: 50 additions & 4 deletions Objects/stringlib/split.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,17 @@ STRINGLIB(split_whitespace)(PyObject* str_obj,
Py_ssize_t maxcount, int prune)
{
Py_ssize_t i, j, k, count=0;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
PyObject *list;
PyObject *sub;

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;

Expand Down Expand Up @@ -111,10 +119,18 @@ STRINGLIB(split_char)(PyObject* str_obj,
Py_ssize_t maxcount, int prune)
{
Py_ssize_t i, j, count=0;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
PyObject *list;
PyObject *sub;
int pruned = 0;

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;

Expand Down Expand Up @@ -169,6 +185,13 @@ STRINGLIB(split)(PyObject* str_obj,
else if (sep_len == 1)
return STRINGLIB(split_char)(str_obj, str, str_len, sep[0], maxcount, prune);

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;
Expand Down Expand Up @@ -214,9 +237,17 @@ STRINGLIB(rsplit_whitespace)(PyObject* str_obj,
Py_ssize_t maxcount, int prune)
{
Py_ssize_t i, j, k, count=0;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
PyObject *list;
PyObject *sub;

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;

Expand Down Expand Up @@ -271,10 +302,18 @@ STRINGLIB(rsplit_char)(PyObject* str_obj,
Py_ssize_t maxcount, int prune)
{
Py_ssize_t i, j, count=0;
PyObject *list = PyList_New(PREALLOC_SIZE(maxcount));
PyObject *list;
PyObject *sub;
int pruned = 0;

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;

Expand Down Expand Up @@ -330,6 +369,13 @@ STRINGLIB(rsplit)(PyObject* str_obj,
else if (sep_len == 1)
return STRINGLIB(rsplit_char)(str_obj, str, str_len, sep[0], maxcount, prune);

if ((str_len == 0) && prune) {
list = PyList_New(0);
if (list == NULL)
return NULL;
return list;
}

list = PyList_New(PREALLOC_SIZE(maxcount));
if (list == NULL)
return NULL;
Expand Down