26 #if !defined(LUA_MAXCAPTURES)
27 #define LUA_MAXCAPTURES 32
32 #define uchar(c) ((unsigned char)(c))
46 if (pos >= 0)
return (
size_t)
pos;
47 else if (0u - (
size_t)pos > len)
return 0;
48 else return len - ((size_t)-pos) + 1;
57 if (start < 1) start = 1;
71 for (i = 0; i <
l; i++)
85 p[i] = tolower(
uchar(s[i]));
98 p[i] = toupper(
uchar(s[i]));
105 #define MAXSIZE ((~(size_t)0) >> 1)
113 else if (l + lsep < l || l + lsep >=
MAXSIZE / n)
114 return luaL_error(L,
"resulting string too large");
116 size_t totallen = n * l + (n - 1) * lsep;
120 memcpy(p, s, l *
sizeof(
char)); p +=
l;
122 memcpy(p, sep, lsep *
sizeof(
char)); p += lsep;
125 memcpy(p, s, l *
sizeof(
char));
138 if (posi < 1) posi = 1;
139 if (pose > l) pose =
l;
140 if (posi > pose)
return 0;
141 n = (
int)(pose - posi + 1);
142 if (posi + n <= pose)
143 return luaL_error(L,
"string slice too long");
156 for (i=1; i<=
n; i++) {
179 return luaL_error(L,
"unable to dump given function");
193 #define CAP_UNFINISHED (-1)
194 #define CAP_POSITION (-2)
216 #if !defined(MAXCCALLS)
217 #define MAXCCALLS 200
222 #define SPECIALS "^$*+?.([%-"
228 return luaL_error(ms->
L,
"invalid capture index %%%d", l + 1);
235 for (level--; level>=0; level--)
237 return luaL_error(ms->
L,
"invalid pattern capture");
267 switch (tolower(cl)) {
268 case 'a' : res = isalpha(c);
break;
269 case 'c' : res = iscntrl(c);
break;
270 case 'd' : res = isdigit(c);
break;
271 case 'g' : res = isgraph(c);
break;
272 case 'l' : res = islower(c);
break;
273 case 'p' : res = ispunct(c);
break;
274 case 's' : res = isspace(c);
break;
275 case 'u' : res = isupper(c);
break;
276 case 'w' : res = isalnum(c);
break;
277 case 'x' : res = isxdigit(c);
break;
278 case 'z' : res = (c == 0);
break;
279 default:
return (cl == c);
281 return (islower(cl) ? res : !
res);
297 else if ((*(p+1) ==
'-') && (p+2 < ec)) {
302 else if (
uchar(*p) == c)
return sig;
318 default:
return (
uchar(*p) == c);
326 if (p >= ms->
p_end - 1)
328 "(missing arguments to " LUA_QL(
"%%b")
")");
329 if (*s != *p)
return NULL;
336 if (--cont == 0)
return s+1;
338 else if (*s == b) cont++;
346 const char *
p,
const char *ep) {
352 const char *
res =
match(ms, (s+i), ep+1);
361 const char *
p,
const char *ep) {
363 const char *
res =
match(ms, s, ep+1);
374 const char *
p,
int what) {
381 if ((res=
match(ms, s, p)) == NULL)
392 if ((res =
match(ms, s, p)) == NULL)
402 if ((
size_t)(ms->
src_end-s) >= len &&
413 if (p != ms->
p_end) {
427 if ((p + 1) != ms->
p_end)
429 s = (s == ms->
src_end) ? s : NULL;
442 const char *ep;
char previous;
446 LUA_QL(
"%%f")
" in pattern");
448 previous = (s == ms->
src_init) ?
'\0' : *(s - 1);
456 case '0':
case '1':
case '2':
case '3':
457 case '4':
case '5':
case '6':
case '7':
458 case '8':
case '9': {
473 if (*ep ==
'*' || *ep ==
'?' || *ep ==
'-') {
474 p = ep + 1;
goto init;
483 if ((res =
match(ms, s + 1, ep + 1)) != NULL)
486 p = ep + 1;
goto init;
500 s++; p = ep;
goto init;
513 static const char *
lmemfind (
const char *s1,
size_t l1,
514 const char *s2,
size_t l2) {
515 if (l2 == 0)
return s1;
516 else if (l2 > l1)
return NULL;
521 while (l1 > 0 && (init = (
const char *)memchr(s1, *s2, l1)) != NULL) {
523 if (memcmp(init, s2+1, l2) == 0)
537 if (i >= ms->
level) {
556 int nlevels = (ms->
level == 0 &&
s) ? 1 : ms->
level;
558 for (i = 0; i < nlevels; i++)
570 upto += strlen(p + upto) + 1;
581 if (init < 1) init = 1;
582 else if (init > ls + 1) {
589 const char *s2 =
lmemfind(s + init - 1, ls - init + 1, p, lp);
598 const char *s1 = s + init - 1;
599 int anchor = (*p ==
'^');
612 if ((res=
match(&ms, s1, p)) != NULL) {
621 }
while (s1++ < ms.
src_end && !anchor);
655 if ((e =
match(&ms, src, p)) != NULL) {
657 if (e == src) newstart++;
681 for (i = 0; i <
l; i++) {
682 if (news[i] !=
L_ESC)
686 if (!isdigit(
uchar(news[i]))) {
687 if (news[i] !=
L_ESC)
689 " in replacement string",
L_ESC);
692 else if (news[i] ==
'0')
704 const char *
e,
int tr) {
740 int anchor = (*p ==
'^');
746 "string/function/table expected");
760 e =
match(&ms, src, p);
793 #if !defined(LUA_INTFRMLEN)
794 #if defined(LUA_USE_LONGLONG)
796 #define LUA_INTFRMLEN "ll"
797 #define LUA_INTFRM_T long long
801 #define LUA_INTFRMLEN "l"
802 #define LUA_INTFRM_T long
813 #if !defined(LUA_FLTFRMLEN)
815 #define LUA_FLTFRMLEN ""
816 #define LUA_FLTFRM_T double
824 #define FLAGS "-+ #0"
829 #define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
837 if (*s ==
'"' || *s ==
'\\' || *s ==
'\n') {
841 else if (*s ==
'\0' || iscntrl(
uchar(*s))) {
843 if (!isdigit(
uchar(*(s+1))))
844 sprintf(buff,
"\\%d", (
int)
uchar(*s));
846 sprintf(buff,
"\\%03d", (
int)
uchar(*s));
857 const char *
p = strfrmt;
858 while (*p !=
'\0' && strchr(
FLAGS, *p) != NULL) p++;
859 if ((
size_t)(p - strfrmt) >=
sizeof(
FLAGS)/
sizeof(
char))
860 luaL_error(L,
"invalid format (repeated flags)");
861 if (isdigit(
uchar(*p))) p++;
862 if (isdigit(
uchar(*p))) p++;
865 if (isdigit(
uchar(*p))) p++;
866 if (isdigit(
uchar(*p))) p++;
868 if (isdigit(
uchar(*p)))
869 luaL_error(L,
"invalid format (width or precision too long)");
871 memcpy(form, strfrmt, (p - strfrmt + 1) *
sizeof(
char));
872 form += p - strfrmt + 1;
881 static void addlenmod (
char *form,
const char *lenmod) {
882 size_t l = strlen(form);
883 size_t lm = strlen(lenmod);
884 char spec = form[l - 1];
885 strcpy(form + l - 1, lenmod);
886 form[l + lm - 1] = spec;
896 const char *strfrmt_end = strfrmt+sfl;
899 while (strfrmt < strfrmt_end) {
900 if (*strfrmt !=
L_ESC)
902 else if (*++strfrmt ==
L_ESC)
911 switch (*strfrmt++) {
916 case 'd':
case 'i': {
921 "not a number in proper range");
923 nb = sprintf(buff, form, ni);
926 case 'o':
case 'u':
case 'x':
case 'X': {
931 "not a non-negative number in proper range");
933 nb = sprintf(buff, form, ni);
936 case 'e':
case 'E':
case 'f':
937 #if defined(LUA_USE_AFORMAT)
940 case 'g':
case 'G': {
952 if (!strchr(form,
'.') && l >= 100) {
959 nb = sprintf(buff, form, s);
966 LUA_QL(
"format"), *(strfrmt - 1));
static const char * lmemfind(const char *s1, size_t l1, const char *s2, size_t l2)
#define luaL_addsize(B, s)
static int nospecials(const char *p, size_t l)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
static int str_dump(lua_State *L)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
static int str_match(lua_State *L)
static int str_reverse(lua_State *L)
LUA_API void lua_replace(lua_State *L, int idx)
static int check_capture(MatchState *ms, int l)
static void push_onecapture(MatchState *ms, int i, const char *s, const char *e)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
GLvoid **typedef void(GLAPIENTRY *PFNGLGETVERTEXATTRIBDVPROC)(GLuint
LUALIB_API const char * luaL_tolstring(lua_State *L, int idx, size_t *len)
static int str_gsub(lua_State *L)
static int matchbracketclass(int c, const char *p, const char *ec)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
LUALIB_API char * luaL_prepbuffsize(luaL_Buffer *B, size_t sz)
static const char * matchbalance(MatchState *ms, const char *s, const char *p)
LUALIB_API const char * luaL_optlstring(lua_State *L, int narg, const char *def, size_t *len)
static void add_value(MatchState *ms, luaL_Buffer *b, const char *s, const char *e, int tr)
static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUA_API int lua_gettop(lua_State *L)
static const char * end_capture(MatchState *ms, const char *s, const char *p)
static int str_char(lua_State *L)
#define lua_tointeger(L, i)
const char * what() const
#define luaL_typename(L, i)
LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *msg)
LUALIB_API void luaL_addstring(luaL_Buffer *B, const char *s)
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
#define luaL_argcheck(L, cond, numarg, extramsg)
static int str_rep(lua_State *L)
static int str_byte(lua_State *L)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
GLdouble GLdouble GLdouble b
LUALIB_API void luaL_pushresultsize(luaL_Buffer *B, size_t sz)
static int str_format(lua_State *L)
#define lua_upvalueindex(i)
static int str_lower(lua_State *L)
static int gmatch_aux(lua_State *L)
LUAMOD_API int luaopen_string(lua_State *L)
LUA_API int lua_isstring(lua_State *L, int idx)
static const char * classend(MatchState *ms, const char *p)
static int push_captures(MatchState *ms, const char *s, const char *e)
LUA_API int lua_toboolean(lua_State *L, int idx)
static int capture_to_close(MatchState *ms)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
static void addquoted(lua_State *L, luaL_Buffer *b, int arg)
LUA_API const char * lua_pushlstring(lua_State *L, const char *s, size_t len)
static const char * max_expand(MatchState *ms, const char *s, const char *p, const char *ep)
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)
static size_t posrelat(ptrdiff_t pos, size_t len)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
static int singlematch(MatchState *ms, const char *s, const char *p, const char *ep)
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
#define luaL_addchar(B, c)
typedef int(WINAPI *PFNWGLRELEASEPBUFFERDCARBPROC)(HPBUFFERARB hPbuffer
void init()
Initializes the gui subsystems.
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
LUA_API void lua_pushnil(lua_State *L)
static const char * start_capture(MatchState *ms, const char *s, const char *p, int what)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
#define lua_pushliteral(L, s)
static int str_find(lua_State *L)
static const char * scanformat(lua_State *L, const char *strfrmt, char *form)
static int str_len(lua_State *L)
static int str_find_aux(lua_State *L, int find)
static const char * match_capture(MatchState *ms, const char *s, int l)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
struct MatchState::@19 capture[LUA_MAXCAPTURES]
static int gmatch(lua_State *L)
static int writer(lua_State *L, const void *b, size_t size, void *B)
LUA_API void lua_pushvalue(lua_State *L, int idx)
#define luaL_newlib(L, l)
static int str_upper(lua_State *L)
#define lua_call(L, n, r)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUA_API void lua_gettable(lua_State *L, int idx)
static void createmetatable(lua_State *L)
static const luaL_Reg strlib[]
#define luaL_checkint(L, n)
LUALIB_API char * luaL_buffinitsize(lua_State *L, luaL_Buffer *B, size_t sz)
bool find(E event, F functor)
Tests whether an event handler is available.
static int str_sub(lua_State *L)
static const char * min_expand(MatchState *ms, const char *s, const char *p, const char *ep)
static const char * match(MatchState *ms, const char *s, const char *p)
static void addlenmod(char *form, const char *lenmod)
struct MatchState MatchState
static int match_class(int c, int cl)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
#define luaL_checkstring(L, n)