lua-users home
lua-l archive

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


On Wed, Mar 11, 2009 at 12:45 PM, Paul Hudson <phudson@pobox.com> wrote:
> I think it should be exactly two hex digits.

Which makes the implementation very straightforward, just 17 extra lines:

llex.c, at line 297 in read_string() after case 'v':

          case 'x': { /*xXX hex escape */
            int i,cu;
            c = 0;
            next(ls);
            for (i = 0; i < 2; i++) {
              cu = toupper(ls->current);
              if (!isxdigit(cu))
                luaX_lexerror(ls, "hex escape too short", TK_STRING);
              if (isdigit(cu))
                c = 16*c + (cu-'0');
              else
                c = 16*c + (cu-'A'+10);
              next(ls);
            }
            save(ls,c);
            continue;
          } break;

Whereas the code for a decimal escape further down is somewhat ambiguous:

              int i = 0;
              c = 0;
              do {
                c = 10*c + (ls->current-'0');
                next(ls);
              } while (++i<3 && isdigit(ls->current));

i.e. it can be cut short, which allows for \0 but also for \23.

steve d.