]> git.ipfire.org Git - thirdparty/LuaJIT.git/commitdiff
Add support for '%a' and '%A' to string.format.
authorMike Pall <mike>
Sat, 25 Aug 2012 20:46:22 +0000 (22:46 +0200)
committerMike Pall <mike>
Sat, 25 Aug 2012 20:46:22 +0000 (22:46 +0200)
src/lib_string.c

index 3dac9d372cb0337803a49a406dee4cb767a52ea1..89ec4f258672b67387011d87191ea8199a7b7bf4 100644 (file)
@@ -780,20 +780,20 @@ LJLIB_CF(string_format)
        addintlen(form);
        sprintf(buff, form, num2uintfrm(L, arg));
        break;
-      case 'e':  case 'E': case 'f': case 'g': case 'G': {
+      case 'e':  case 'E': case 'f': case 'g': case 'G': case 'a': case 'A': {
        TValue tv;
        tv.n = lj_lib_checknum(L, arg);
        if (LJ_UNLIKELY((tv.u32.hi << 1) >= 0xffe00000)) {
          /* Canonicalize output of non-finite values. */
          char *p, nbuf[LJ_STR_NUMBUF];
          size_t len = lj_str_bufnum(nbuf, &tv);
-         if (strfrmt[-1] == 'E' || strfrmt[-1] == 'G') {
+         if (strfrmt[-1] < 'a') {
            nbuf[len-3] = nbuf[len-3] - 0x20;
            nbuf[len-2] = nbuf[len-2] - 0x20;
            nbuf[len-1] = nbuf[len-1] - 0x20;
          }
          nbuf[len] = '\0';
-         for (p = form; *p < 'e' && *p != '.'; p++) ;
+         for (p = form; *p < 'A' && *p != '.'; p++) ;
          *p++ = 's'; *p = '\0';
          sprintf(buff, form, nbuf);
          break;