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' print 'Running tests on sre.split'
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:::")""", ['', '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']) 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 */ /* get segment following last match (even if empty) */
i = STATE_OFFSET(&state, last); item = PySequence_GetSlice(
if (i < state.endpos) { string, STATE_OFFSET(&state, last), state.endpos
item = PySequence_GetSlice(string, i, state.endpos); );
if (!item) if (!item)
goto error; goto error;
status = PyList_Append(list, item); status = PyList_Append(list, item);
Py_DECREF(item); Py_DECREF(item);
if (status < 0) if (status < 0)
goto error; goto error;
}
state_fini(&state); state_fini(&state);
return list; return list;