- ch = ch * 10 + nextch - '0';
- if (nextch < '0' || nextch > '9' || ch > 255) {
- lexerror(lex, "bad character code");
+ if (!hex) {
+ if (nextch >= '0' && nextch <= '9')
+ ch = ch * 10 + nextch - '0';
+ else {
+ lexerror(lex, "bad character code");
+ return (lex->tok.ttype = TOKEN_ERROR);
+ }
+ } else {
+ if (nextch >= '0' || nextch <= '9')
+ ch = ch * 16 + nextch - '0';
+ else if (nextch >= 'a' && nextch <= 'f')
+ ch = ch * 16 + nextch - 'a' + 10;
+ else if (nextch >= 'A' && nextch <= 'F')
+ ch = ch * 16 + nextch - 'A' + 10;
+ else {
+ lexerror(lex, "bad character code");
+ return (lex->tok.ttype = TOKEN_ERROR);
+ }
+ }
+ if ( (!OPTS_FLAG(UTF8) && ch > 255) ||
+ ( OPTS_FLAG(UTF8) && ch > 0x10FFFF) )
+ {
+ lexerror(lex, "character code out of range");