From 2363a9f8faa3abfdfde6adec5c1dc0c816016731 Mon Sep 17 00:00:00 2001 From: Bruce Korb Date: Mon, 29 Dec 2008 22:00:19 +0100 Subject: [PATCH] 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 --- ChangeLog | 5 +++++ lib/parse-duration.c | 38 ++++++++++++-------------------------- lib/parse-duration.h | 6 ++++-- 3 files changed, 21 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8bd92e7c09..d61634eff7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2008-11-17 Bruce Korb + + * 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 wchar.h: supply WEOF on Irix 5.3 diff --git a/lib/parse-duration.c b/lib/parse-duration.c index 91f5291c5b..561bd98adb 100644 --- a/lib/parse-duration.c +++ b/lib/parse-duration.c @@ -566,38 +566,24 @@ parse_non_iso8601(cch_t * pz) 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; - } - - if (*pz == 'T') - { - res = parse_time (pz + 1); - if (res == BAD_TIME) - break; - return res; - } - - if (! isdigit ((unsigned char)*pz)) - break; + switch (*pz) + { + case 'P': + return parse_period (pz + 1); - res = parse_non_iso8601 (pz); - if (res != BAD_TIME) - return res; + case 'T': + return parse_time (pz + 1); - } while (0); + default: + if (isdigit ((unsigned char)*pz)) + return parse_non_iso8601 (pz); - return BAD_TIME; + errno = EINVAL; + return BAD_TIME; + } } /* diff --git a/lib/parse-duration.h b/lib/parse-duration.h index fbc732ff39..beab3cf66b 100644 --- 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. -- 2.30.2