Browse Source

'%' must be '%%' to avoid formatting problems

Roberto Ierusalimschy 21 năm trước cách đây
mục cha
commit
24434b59f7
1 tập tin đã thay đổi với 5 bổ sung5 xóa
  1. 5 5
      lstrlib.c

+ 5 - 5
lstrlib.c

@@ -1,5 +1,5 @@
 /*
-** $Id: lstrlib.c,v 1.99 2003/05/14 14:35:54 roberto Exp roberto $
+** $Id: lstrlib.c,v 1.100 2003/10/07 20:13:41 roberto Exp roberto $
 ** Standard library for string operations and pattern-matching
 ** See Copyright Notice in lua.h
 */
@@ -200,7 +200,7 @@ static const char *luaI_classend (MatchState *ms, const char *p) {
   switch (*p++) {
     case ESC: {
       if (*p == '\0')
-        luaL_error(ms->L, "malformed pattern (ends with `%')");
+        luaL_error(ms->L, "malformed pattern (ends with `%%')");
       return p+1;
     }
     case '[': {
@@ -682,7 +682,7 @@ static const char *scanformat (lua_State *L, const char *strfrmt,
     luaL_error(L, "invalid format (width or precision too long)");
   if (p-strfrmt+2 > MAX_FORMAT)  /* +2 to include `%' and the specifier */
     luaL_error(L, "invalid format (too long)");
-  form[0] = '%';
+  form[0] = ESC;
   strncpy(form+1, strfrmt, p-strfrmt+1);
   form[p-strfrmt+2] = 0;
   return p;
@@ -697,9 +697,9 @@ static int str_format (lua_State *L) {
   luaL_Buffer b;
   luaL_buffinit(L, &b);
   while (strfrmt < strfrmt_end) {
-    if (*strfrmt != '%')
+    if (*strfrmt != ESC)
       luaL_putchar(&b, *strfrmt++);
-    else if (*++strfrmt == '%')
+    else if (*++strfrmt == ESC)
       luaL_putchar(&b, *strfrmt++);  /* %% */
     else { /* format item */
       char form[MAX_FORMAT];  /* to store the format (`%...') */