This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [RFA]: Charconst reprise
- To: Neil Booth <neil at daikokuya dot demon dot co dot uk>
- Subject: Re: [RFA]: Charconst reprise
- From: Fergus Henderson <fjh at cs dot mu dot oz dot au>
- Date: Wed, 7 Mar 2001 15:37:37 +1100
- Cc: gcc-patches at gcc dot gnu dot org
- References: <20010306191937.C28857@daikokuya.demon.co.uk>
On 06-Mar-2001, Neil Booth <neil@daikokuya.demon.co.uk> wrote:
> +static unsigned int
> +read_ucs (pfile, pstr, limit, length)
...
> +{
...
> + if (! ISXDIGIT (c))
> + {
> + cpp_error (pfile,
> + "non-hex digit '%c' in universal-character-name", c);
> + break;
> + }
...
> + if (c >= 'a' && c <= 'f')
> + code += c - 'a' + 10;
> + if (c >= 'A' && c <= 'F')
> + code += c - 'A' + 10;
> + if (c >= '0' && c <= '9')
> + code += c - '0';
...
> +static unsigned int
> +parse_escape (pfile, pstr, limit, mask, traditional)
...
> +{
> + if (c >= '0' && c <= '9')
> + digit = c - '0';
> + else if (c >= 'a' && c <= 'f')
> + digit = c - 'a' + 10;
> + else if (c >= 'A' && c <= 'F')
> + digit = c - 'A' + 10;
> + else
> + break;
That code to figure out the numerical value of a hexadecimal digit is
duplicated. I think it would be nicer to make it a separate function,
e.g.
int
hex_digit_value (int c)
{
if (c >= '0' && c <= '9')
return c - '0';
else if (c >= 'a' && c <= 'f')
return c - 'a' + 10;
else if (c >= 'A' && c <= 'F')
return c - 'A' + 10;
else
abort ();
}
and then use
code += hex_digit_value (c);
in read_ucs() and
if (ISXDIGIT (c))
digit = hex_digit_value (c);
else
break;
in parse_escape().
--
Fergus Henderson <fjh@cs.mu.oz.au> | "I have always known that the pursuit
| of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh> | -- the last words of T. S. Garp.