sre.split should return the last segment, even if empty

(sorry, barry)
This commit is contained in:
Fredrik Lundh 2001-10-22 06:01:56 +00:00
parent 5c66a26dee
commit f864aa8fd9
2 changed files with 11 additions and 11 deletions

View File

@ -155,6 +155,7 @@ if verbose:
print 'Running tests on sre.split'
test(r"""sre.split(r":", ":a:b::c")""", ['', 'a', 'b', '', 'c'])
test(r"""sre.split(r":+", ":a:b:::")""", ['', 'a', 'b', ''])
test(r"""sre.split(r":*", ":a:b::c")""", ['', 'a', 'b', 'c'])
test(r"""sre.split(r"(:*)", ":a:b::c")""", ['', ':', 'a', ':', 'b', '::', 'c'])
test(r"""sre.split(r"(?::*)", ":a:b::c")""", ['', 'a', 'b', 'c'])

View File

@ -2007,17 +2007,16 @@ pattern_split(PatternObject* self, PyObject* args, PyObject* kw)
}
/* get segment following last match */
i = STATE_OFFSET(&state, last);
if (i < state.endpos) {
item = PySequence_GetSlice(string, i, state.endpos);
if (!item)
goto error;
status = PyList_Append(list, item);
Py_DECREF(item);
if (status < 0)
goto error;
}
/* get segment following last match (even if empty) */
item = PySequence_GetSlice(
string, STATE_OFFSET(&state, last), state.endpos
);
if (!item)
goto error;
status = PyList_Append(list, item);
Py_DECREF(item);
if (status < 0)
goto error;
state_fini(&state);
return list;