diff options
author | Sergey Poznyakoff <gray@gnu.org> | 2019-05-13 14:24:58 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org> | 2019-05-13 14:52:18 +0300 |
commit | 07930c5ee74b8d2645fc55465833ab84e2f4444a (patch) | |
tree | 45ca5b8b787987a9c6a5980bddd7d6db13e070c7 /src | |
parent | 3e07e3ad30e8a7a091e213eb4df839b7cf7f1e64 (diff) | |
download | grecs-07930c5ee74b8d2645fc55465833ab84e2f4444a.tar.gz grecs-07930c5ee74b8d2645fc55465833ab84e2f4444a.tar.bz2 |
wordsplit: return single empty string on empty input in WRDSF_NOSPLIT mode
* src/wordsplit.c (wordsplit_finish): Make sure at one non-null
argument is always returned in WRDSF_NOSPLIT mode.
* tests/wordsplit.at: Add new test.
Diffstat (limited to 'src')
-rw-r--r-- | src/wordsplit.c | 39 |
1 files changed, 25 insertions, 14 deletions
diff --git a/src/wordsplit.c b/src/wordsplit.c index f94015a..e979f27 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c @@ -805,25 +805,35 @@ wordsplit_finish (struct wordsplit *wsp) n++; } - if (n == 0 && (wsp->ws_flags & WRDSF_INCREMENTAL)) + if (n == 0) { - /* The loop above have eliminated all nodes. Restart the - processing, if there's any input left. */ - if (wsp->ws_endp < wsp->ws_len) + /* The loop above have eliminated all nodes. */ + if (wsp->ws_flags & WRDSF_INCREMENTAL) { - int rc; - if (wsp->ws_flags & WRDSF_SHOWDBG) - wsp->ws_debug (_("Restarting")); - rc = wordsplit_process_list (wsp, skip_delim (wsp)); - if (rc) - return rc; + /* Restart the processing, if there's any input left. */ + if (wsp->ws_endp < wsp->ws_len) + { + int rc; + if (wsp->ws_flags & WRDSF_SHOWDBG) + wsp->ws_debug (_("Restarting")); + rc = wordsplit_process_list (wsp, skip_delim (wsp)); + if (rc) + return rc; + } + else + { + wsp->ws_error = WRDSE_EOF; + return WRDSE_EOF; + } + goto again; } - else + + if (wsp->ws_flags & WRDSF_NOSPLIT) { - wsp->ws_error = WRDSE_EOF; - return WRDSE_EOF; + if (wordsplit_add_segm (wsp, 0, 0, _WSNF_EMPTYOK)) + return wsp->ws_errno; + n = 1; } - goto again; } if (alloc_space (wsp, n + 1)) @@ -2412,6 +2422,7 @@ wordsplit_process_list (struct wordsplit *wsp, size_t start) } } } + return wsp->ws_errno; } |