Mercurial > hg > octave-lyh > gnulib-hg
changeset 10978:1780a93bb27f
parse-duration: small doc tweak and coding aesthetics issue.
* lib/parse-duration.h: non-iso form accepts years, months weeks, too
* lib/parse-duration.c: use a switch instead of cascading if's.
Signed-off-by: Ralf Wildenhues <Ralf.Wildenhues@gmx.de>
author | Bruce Korb <bkorb@gnu.org> |
---|---|
date | Mon, 29 Dec 2008 22:00:19 +0100 |
parents | 6183b030f375 |
children | 03e819eea554 |
files | ChangeLog lib/parse-duration.c lib/parse-duration.h |
diffstat | 3 files changed, 22 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-11-17 Bruce Korb <bkorb@gnu.org> + + * lib/parse-duration.h: non-iso form accepts years, months weeks, too + * lib/parse-duration.c: use a switch instead of cascading if's. + 2008-12-29 Eric Blake <ebb9@byu.net> wchar.h: supply WEOF on Irix 5.3
--- a/lib/parse-duration.c +++ b/lib/parse-duration.c @@ -566,38 +566,24 @@ time_t parse_duration (char const * pz) { - time_t res = 0; - while (isspace ((unsigned char)*pz)) pz++; - do { - if (*pz == 'P') - { - res = parse_period (pz + 1); - if (res == BAD_TIME) - break; - return res; - } + switch (*pz) + { + case 'P': + return parse_period (pz + 1); + + case 'T': + return parse_time (pz + 1); - if (*pz == 'T') - { - res = parse_time (pz + 1); - if (res == BAD_TIME) - break; - return res; - } + default: + if (isdigit ((unsigned char)*pz)) + return parse_non_iso8601 (pz); - if (! isdigit ((unsigned char)*pz)) - break; - - res = parse_non_iso8601 (pz); - if (res != BAD_TIME) - return res; - - } while (0); - - return BAD_TIME; + errno = EINVAL; + return BAD_TIME; + } } /*
--- a/lib/parse-duration.h +++ b/lib/parse-duration.h @@ -28,10 +28,12 @@ ==== if it is a digit - the string may contain: NNN d NNN h NNN m NNN s - This represents NNN days, NNN hours, NNN minutes and NNN seconds. + the string may contain: NNN Y NNN M NNN W NNN d NNN h NNN m NNN s + This represents NNN years, NNN months, NNN weeks, NNN days, NNN hours, + NNN minutes and NNN seconds. The embeded white space is optional. These terms must appear in this order. + Case is significant: 'M' is months and 'm' is minutes. The final "s" is optional. All of the terms ("NNN" plus designator) are optional. Minutes and seconds may optionally be represented as NNN:NNN.