On Mon, 6 Feb 2017 13:29:54 -0800
Evan Gates <evan.gates_AT_gmail.com> wrote:
> On Sat, Feb 4, 2017 at 1:32 PM, Mattias Andrée
> <maandree_AT_kth.se> wrote:
> > _AT_@ -39,10 +39,8 @@ unescape(char *s)
> > off += m - i - 1;
> > for (--m, q = 0, factor = 1; m
> > > i + 1; m--) {
> > - if (s[m] >= '0' && s[m]
> > <= '9')
> > - q += (s[m] -
> > '0') * factor;
> > - else if (s[m] >= 'A' &&
> > s[m] <= 'F')
> > - q += ((s[m] -
> > 'A') + 10) * factor;
> > - else if (s[m] >= 'a' &&
> > s[m] <= 'f')
> > - q += ((s[m] -
> > 'a') + 10) * factor;
> > + if (isdigit(s[m]))
> > + q += (s[m] &
> > 15) * factor;
> > + else
> > + q += ((s[m] &
> > 15) + 9) * factor; factor *= 16;
> > }
> > --
> > 2.11.0
> >
> >
>
> I think this would be clearer as:
>
> if (isdigit(s[m]))
> q += (s[m] - '0') * factor;
> else
> q += (tolower(s[m]) - 'a' + 10) * factor;
>
> But it is just a personal style preference. Or, if we do
> keep the bit twiddling, I highly recommend using hex
> instead of decimal, e.g. (s[m] & 0xf).
>
> Thoughts?
I don't really have a prefers.
Received on Mon Feb 06 2017 - 22:35:04 CET