From 8e0253af022abe9f9225352aae1088d6621a81ab Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Dec 2019 18:25:08 +0000 Subject: 45138: Add zformat unit tests. --- Src/Modules/zutil.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index 24659cb16..de5fe8034 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -913,13 +913,13 @@ bin_zformat(char *nam, char **args, UNUSED(Options ops), UNUSED(int func)) switch (opt) { case 'f': { - char **ap, *specs[256], *out; + char **ap, *specs[256] = {0}, *out; int olen, oused = 0; - memset(specs, 0, 256 * sizeof(char *)); - specs['%'] = "%"; specs[')'] = ")"; + + /* Parse the specs in argv. */ for (ap = args + 2; *ap; ap++) { if (!ap[0][0] || ap[0][0] == '-' || ap[0][0] == '.' || idigit(ap[0][0]) || ap[0][1] != ':') { -- cgit v1.2.3 From 525faae5498adb4b4f1c0f4657b9ef71fc31c4d6 Mon Sep 17 00:00:00 2001 From: Daniel Shahaf Date: Tue, 24 Dec 2019 18:25:09 +0000 Subject: 45137: zformat: Allow the specifying minimum width and a dot with an empty maximum width. Before this commit, format specs such as '%5.s' would be printed literally. Now, they are treated as equivalent to '%5s'. The '.' character is not allowed to be used in specs, so there is no incompatibility. --- ChangeLog | 4 ++++ Src/Modules/zutil.c | 3 +-- Test/V13zformat.ztst | 2 ++ 3 files changed, 7 insertions(+), 2 deletions(-) (limited to 'Src/Modules/zutil.c') diff --git a/ChangeLog b/ChangeLog index fe3b6951c..321216c7a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,9 @@ 2019-12-26 Daniel Shahaf + * 45137: Src/Modules/zutil.c, Test/V13zformat.ztst: zformat: + Allow the specifying minimum width and a dot with an empty + maximum width. + * 45138: Src/Modules/zutil.c, Test/V13zformat.ztst: Add zformat unit tests. diff --git a/Src/Modules/zutil.c b/Src/Modules/zutil.c index de5fe8034..7d9bf05d6 100644 --- a/Src/Modules/zutil.c +++ b/Src/Modules/zutil.c @@ -797,8 +797,7 @@ static char *zformat_substring(char* instr, char **specs, char **outp, if ((*s == '.' || testit) && idigit(s[1])) { for (max = 0, s++; idigit(*s); s++) max = (max * 10) + (int) STOUC(*s) - '0'; - } - else if (testit) + } else if (*s == '.' || testit) s++; if (testit && STOUC(*s)) { diff --git a/Test/V13zformat.ztst b/Test/V13zformat.ztst index d8de2bb04..982866e13 100644 --- a/Test/V13zformat.ztst +++ b/Test/V13zformat.ztst @@ -17,12 +17,14 @@ zformat_and_print_s '%s' foo zformat_and_print_s '%5s' min zformat_and_print_s '%-5s' neg + zformat_and_print_s '%5.s' empty zformat_and_print_s '%.5s' max zformat_and_print_s '%.5s' truncated 0:basic zformat test >'foo' >'min ' >' neg' +>'empty' >'max' >'trunc' -- cgit v1.2.3