--- /python/branches/release25-maint/Modules/_sre.c Mon Feb 04 22:00:35 2008 +++ /python/branches/release25-maint/Modules/_sre.c Thu Jul 03 01:31:16 2008 @@ -2171,6 +2171,7 @@ Py_ssize_t n; Py_ssize_t i; void* last; + int suppress_empty; PyObject* string; Py_ssize_t maxsplit = 0; @@ -2191,6 +2192,7 @@ n = 0; last = state.start; + suppress_empty = 0; while (!maxsplit || n < maxsplit) { @@ -2216,41 +2218,51 @@ goto error; } - if (state.start == state.ptr) { - if (last == state.end) - break; + if (state.start == state.ptr && last == state.end) + break; + + if(state.start < state.ptr) + suppress_empty = 0; + + if(! suppress_empty) { + /* get segment before this match */ + item = PySequence_GetSlice( + string, STATE_OFFSET(&state, last), + STATE_OFFSET(&state, state.start) + ); + if (!item) + goto error; + status = PyList_Append(list, item); + Py_DECREF(item); + if (status < 0) + goto error; + + /* add groups (if any) */ + for (i = 0; i < self->groups; i++) { + item = state_getslice(&state, i+1, string, 0); + if (!item) + goto error; + status = PyList_Append(list, item); + Py_DECREF(item); + if (status < 0) + goto error; + } + + n = n + 1; + } + + last = state.ptr; + + if (state.start == state.ptr) { /* skip one character */ state.start = (void*) ((char*) state.ptr + state.charsize); - continue; + suppress_empty = 0; } - - /* get segment before this match */ - item = PySequence_GetSlice( - string, STATE_OFFSET(&state, last), - STATE_OFFSET(&state, state.start) - ); - if (!item) - goto error; - status = PyList_Append(list, item); - Py_DECREF(item); - if (status < 0) - goto error; - - /* add groups (if any) */ - for (i = 0; i < self->groups; i++) { - item = state_getslice(&state, i+1, string, 0); - if (!item) - goto error; - status = PyList_Append(list, item); - Py_DECREF(item); - if (status < 0) - goto error; - } - - n = n + 1; - - last = state.start = state.ptr; - + else + { + state.start = state.ptr; + suppress_empty = 1; + } } /* get segment following last match (even if empty) */