This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: [RFA]: Charconst reprise


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.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]