column: fix outputing empty column at the end of line

The following commands manifests the problem.  In old versions before
commit 4762ae9d60 ("column: use libsmartcols for --table"), both of them
should output with 2 "|"

	echo '||'  | column -o '|' -s '|' -t
	echo '|| ' | column -o '|' -s '|' -t

Fixes: 4762ae9d60 ("column: use libsmartcols for --table")
Signed-off-by: Yousong Zhou <zhouyousong@yunionyun.com>
Reviewed-by: Sami Kerola <kerolasa@iki.fi>
This commit is contained in:
Yousong Zhou 2019-07-29 01:24:29 +00:00 committed by Karel Zak
parent 8bad603ae0
commit 325bfd53e8
4 changed files with 11 additions and 1 deletions

View File

@ -0,0 +1 @@
|

View File

@ -0,0 +1 @@
||

View File

@ -116,4 +116,12 @@ ts_init_subtest "empty-column"
printf ':a:b\n' | $TS_CMD_COLUMN --table --separator ':' --output-separator ':' >> $TS_OUTPUT 2>&1
ts_finalize_subtest
ts_init_subtest "empty-column-at-eol"
printf '|' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1
ts_finalize_subtest
ts_init_subtest "empty-column-at-eol2"
printf '||' | $TS_CMD_COLUMN --separator '|' --output-separator '|' --table >> $TS_OUTPUT 2>&1
ts_finalize_subtest
ts_finalize

View File

@ -169,7 +169,7 @@ static wchar_t *local_wcstok(wchar_t *p, const wchar_t *separator, int greedy, w
return strtok_r(p, separator, state);
#endif
if (!p) {
if (!*state || !**state)
if (!*state)
return NULL;
p = *state;
}