libc: ignore '?' in date format strings

Ignoring '?' when formatting date strings allows
the format strings to be reused for parsing. This
is convenient, since we don't need to duplicate
the format strings.
This commit is contained in:
Ori Bernstein 2020-09-22 19:24:01 -07:00
parent 77c3cb50fb
commit 9f8d62ab64
2 changed files with 7 additions and 3 deletions

View file

@ -134,8 +134,7 @@ For example,
will format to a width of 3. When parsing, this acts as whitespace.
.TP
.B ?
When parsing, this makes the following argument match fuzzily.
Fuzzy matching means that all formats are tried, from most to least specific.
When parsing, all formats of the following argument are tried from most to least specific.
For example,
.I ?M
will match
@ -144,7 +143,9 @@ will match
.IR 01 ,
and
.IR 1 ,
in that order of preference.
in that order. When formatting,
.B ?
is ignored.
.TP
.B ~
When parsing a date, this slackens range enforcement, accepting

View file

@ -428,6 +428,9 @@ static int
switch(c0){
case 0:
break;
/* Ignore '?' so we can share parse and format strings */
case '?':
continue;
case 'Y':
switch(w){
case 1: n += fmtprint(f, "%*d", pad, tm->year + 1900); break;