implement %y and %C specifiers in strptime
This commit is contained in:
parent
9c2d437cb3
commit
348fc5561c
1 changed files with 10 additions and 4 deletions
|
|
@ -11,6 +11,7 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
||||||
int i, w, neg, adj, min, range, *dest, dummy;
|
int i, w, neg, adj, min, range, *dest, dummy;
|
||||||
const char *ex;
|
const char *ex;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
int want_century = 0, century = 0;
|
||||||
while (*f) {
|
while (*f) {
|
||||||
if (*f != '%') {
|
if (*f != '%') {
|
||||||
if (isspace(*f)) for (; *s && isspace(*s); s++);
|
if (isspace(*f)) for (; *s && isspace(*s); s++);
|
||||||
|
|
@ -40,9 +41,9 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
/* FIXME */
|
dest = ¢ury;
|
||||||
dest = &dummy;
|
|
||||||
if (w<0) w=2;
|
if (w<0) w=2;
|
||||||
|
want_century |= 2;
|
||||||
goto numeric_digits;
|
goto numeric_digits;
|
||||||
case 'd': case 'e':
|
case 'd': case 'e':
|
||||||
dest = &tm->tm_mday;
|
dest = &tm->tm_mday;
|
||||||
|
|
@ -135,14 +136,15 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
||||||
if (!s) return 0;
|
if (!s) return 0;
|
||||||
break;
|
break;
|
||||||
case 'y':
|
case 'y':
|
||||||
/* FIXME */
|
dest = &tm->tm_year;
|
||||||
dest = &dummy;
|
|
||||||
w = 2;
|
w = 2;
|
||||||
|
want_century |= 1;
|
||||||
goto numeric_digits;
|
goto numeric_digits;
|
||||||
case 'Y':
|
case 'Y':
|
||||||
dest = &tm->tm_year;
|
dest = &tm->tm_year;
|
||||||
if (w<0) w=4;
|
if (w<0) w=4;
|
||||||
adj = 1900;
|
adj = 1900;
|
||||||
|
want_century = 0;
|
||||||
goto numeric_digits;
|
goto numeric_digits;
|
||||||
case '%':
|
case '%':
|
||||||
if (*s++ != '%') return 0;
|
if (*s++ != '%') return 0;
|
||||||
|
|
@ -187,5 +189,9 @@ char *strptime(const char *restrict s, const char *restrict f, struct tm *restri
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (want_century) {
|
||||||
|
if (want_century & 2) tm->tm_year += century * 100 - 1900;
|
||||||
|
else if (tm->tm_year <= 68) tm->tm_year += 100;
|
||||||
|
}
|
||||||
return (char *)s;
|
return (char *)s;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue