libc: tmparse should ignore leading whitespace

We almost always want to skip leading whitespace in time
formats, so make tmparse just do it. This fixes upas mbox
parsing, which leaves a leading whitespace at the start of
the date.
This commit is contained in:
Ori Bernstein 2020-08-26 10:23:00 -07:00
parent 8727bfd9bd
commit 17abfa51ca
2 changed files with 16 additions and 1 deletions

View file

@ -65,6 +65,7 @@ Tmstime is identical to tmtime, but accepts the time in sec-
onds. onds.
.PP .PP
Tmparse parses a time from a string according to the format argument. Tmparse parses a time from a string according to the format argument.
Leading whitespace is ignored.
The point at which the parsing stopped is returned in The point at which the parsing stopped is returned in
.IR ep . .IR ep .
If If

View file

@ -632,6 +632,20 @@ tmparse(Tm *tm, char *fmt, char *str, Tzone *tz, char **ep)
sloppy = 1; sloppy = 1;
p++; p++;
} }
/* Skip whitespace */
for(;; p++) {
switch(*p) {
case ' ':
case '\t':
case '\n':
case '\f':
case '\r':
case '\v':
continue;
}
break;
}
while(*p){ while(*p){
w = 1; w = 1;
c0 = *p++; c0 = *p++;
@ -868,7 +882,6 @@ Zoneparsed:
case '_': case '_':
case ',': case ',':
case ' ': case ' ':
if(*s != ' ' && *s != '\t' && *s != ',' && *s != '\n' && *s != '\0') if(*s != ' ' && *s != '\t' && *s != ',' && *s != '\n' && *s != '\0')
goto baddate; goto baddate;
p += strspn(p, " ,_\t\n"); p += strspn(p, " ,_\t\n");
@ -884,6 +897,7 @@ Zoneparsed:
if(!ok) if(!ok)
goto baddate; goto baddate;
} }
if(*p != '\0') if(*p != '\0')
goto baddate; goto baddate;
if(ep != nil) if(ep != nil)