MCPcopy Create free account
hub / github.com/DFHack/dfhack / scanformat

Function scanformat

depends/lua/src/lstrlib.c:981–1000  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

979
980
981static const char *scanformat (lua_State *L, const char *strfrmt, char *form) {
982 const char *p = strfrmt;
983 while (*p != '\0' && strchr(FLAGS, *p) != NULL) p++; /* skip flags */
984 if ((size_t)(p - strfrmt) >= sizeof(FLAGS)/sizeof(char))
985 luaL_error(L, "invalid format (repeated flags)");
986 if (isdigit(uchar(*p))) p++; /* skip width */
987 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
988 if (*p == '.') {
989 p++;
990 if (isdigit(uchar(*p))) p++; /* skip precision */
991 if (isdigit(uchar(*p))) p++; /* (2 digits at most) */
992 }
993 if (isdigit(uchar(*p)))
994 luaL_error(L, "invalid format (width or precision too long)");
995 *(form++) = '%';
996 memcpy(form, strfrmt, ((p - strfrmt) + 1) * sizeof(char));
997 form += (p - strfrmt) + 1;
998 *form = '\0';
999 return p;
1000}
1001
1002
1003/*

Callers 1

str_formatFunction · 0.85

Calls 1

luaL_errorFunction · 0.85

Tested by

no test coverage detected