bug-gnulib
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: parse-duration.c


From: Bruce Korb
Subject: Re: parse-duration.c
Date: Sat, 27 Dec 2008 14:36:56 -0800
User-agent: Thunderbird 2.0.0.18 (X11/20081112)

Bruce Korb wrote:
> So, I've now had another gander now, too.
> A small doc tweak and coding aesthetics issue:

This should probably be applied.  I don't have "push" privs on the
repository.  What should I do?  Thanks. - Bruce

> $ diff -up gnulib/ChangeLog gnulib-clone/ChangeLog
> --- gnulib/ChangeLog    2008-12-21 08:47:26.000000000 -0800
> +++ gnulib-clone/ChangeLog      2008-12-21 11:50:18.000000000 -0800
> @@ -1,3 +1,8 @@
> +2008-11-17  Bruce Korb  <address@hidden>
> +
> +       * 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-21  Bruno Haible  <address@hidden>
> 
>         Work around a btowc() bug on IRIX 6.5.
> $ diff -up gnulib/lib/parse-duration.c gnulib-clone/lib/parse-duration.c
> --- gnulib/lib/parse-duration.c 2008-12-21 08:47:26.000000000 -0800
> +++ gnulib-clone/lib/parse-duration.c   2008-12-21 11:37:45.000000000 -0800
> @@ -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;
> -
> -    res = parse_non_iso8601 (pz);
> -    if (res != BAD_TIME)
> -      return res;
> -
> -  } while (0);
> -
> -  return BAD_TIME;
> +  switch (*pz)
> +    {
> +    case 'P':
> +      return parse_period (pz + 1);
> +
> +    case 'T':
> +      return parse_time (pz + 1);
> +
> +    default:
> +      if (isdigit ((unsigned char)*pz))
> +        return parse_non_iso8601 (pz);
> +
> +      errno = EINVAL;
> +      return BAD_TIME;
> +    }
>  }
> 
>  /*
> $ diff -up gnulib/lib/parse-duration.h gnulib-clone/lib/parse-duration.h
> --- gnulib/lib/parse-duration.h 2008-12-21 08:47:26.000000000 -0800
> +++ gnulib-clone/lib/parse-duration.h   2008-12-21 11:41:19.000000000 -0800
> @@ -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.
> 





reply via email to

[Prev in Thread] Current Thread [Next in Thread]