static void waddintlen (lua_WChar *form) { size_t l = lua_WChar_len(form); lua_WChar spec = form[l - 1]; lua_WChar_ncpy(form + l - 1, wLUA_INTFRMLEN, l); form[l + sizeof(LUA_INTFRMLEN) - 2] = spec; form[l + sizeof(LUA_INTFRMLEN) - 1] = '\0'; }
static const lua_WChar *wscanformat (lua_State *L, const lua_WChar *strfrmt, lua_WChar *form) { const lua_WChar *p = strfrmt; while (*p != '\0' && lua_WChar_chr(wFLAGS, *p) != NULL) p++; /* skip flags */ if ((size_t)(p - strfrmt) >= sizeof(FLAGS)) luaL_error(L, "invalid format (repeated flags)"); if (iswdigit(*p)) p++; /* skip width */ if (iswdigit(*p)) p++; /* (2 digits at most) */ if (*p == '.') { p++; if (iswdigit(*p)) p++; /* skip precision */ if (iswdigit(*p)) p++; /* (2 digits at most) */ } if (iswdigit(*p)) luaL_error(L, "invalid format (width or precision too long)"); *(form++) = '%'; lua_WChar_ncpy(form, strfrmt, p - strfrmt + 1); form += p - strfrmt + 1; *form = '\0'; return p; }
static const lua_WChar *scanformat (lua_State *L, const lua_WChar *strfrmt, lua_WChar *form, int *hasprecision) { const lua_WChar *p = strfrmt; while (lua_WChar_chr(L"-+ #0", *p)) p++; /* skip flags */ if (iswdigit(*p)) p++; /* skip width */ if (iswdigit(*p)) p++; /* (2 digits at most) */ if (*p == '.') { p++; *hasprecision = 1; if (iswdigit(*p)) p++; /* skip precision */ if (iswdigit(*p)) p++; /* (2 digits at most) */ } if (iswdigit(*p)) 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] = '%'; lua_WChar_ncpy(form+1, strfrmt, p-strfrmt+1); form[p-strfrmt+2] = 0; return p; }