24#define uchar(c) ((unsigned char)(c))
36static ptrdiff_t
posrelat (ptrdiff_t pos,
size_t len) {
38 if (pos < 0) pos += (ptrdiff_t)len + 1;
39 return (pos >= 0) ? pos : 0;
48 if (start < 1) start = 1;
49 if (end > (ptrdiff_t)l) end = (ptrdiff_t)l;
112 if (posi <= 0) posi = 1;
113 if ((
size_t)pose > l) pose = l;
114 if (posi > pose)
return 0;
115 n = (int)(pose - posi + 1);
116 if (posi + n <= pose)
130 for (i=1; i<=n; i++) {
153 luaL_error(L,
"unable to dump given function");
167#define CAP_UNFINISHED (-1)
168#define CAP_POSITION (-2)
183#define SPECIALS "^$*+?.([%-"
195 int level = ms->
level;
196 for (level--; level>=0; level--)
198 return luaL_error(ms->
L,
"invalid pattern capture");
214 if (*(p++) ==
L_ESC && *p !=
'\0')
228 switch (tolower(cl)) {
229 case 'a' : res = isalpha(c);
break;
230 case 'c' : res = iscntrl(c);
break;
231 case 'd' : res = isdigit(c);
break;
232 case 'l' : res = islower(c);
break;
233 case 'p' : res = ispunct(c);
break;
234 case 's' : res = isspace(c);
break;
235 case 'u' : res = isupper(c);
break;
236 case 'w' : res = isalnum(c);
break;
237 case 'x' : res = isxdigit(c);
break;
238 case 'z' : res = (c == 0);
break;
239 default:
return (cl == c);
241 return (islower(cl) ? res : !res);
257 else if ((*(p+1) ==
'-') && (p+2 < ec)) {
262 else if (
uchar(*p) == c)
return sig;
273 default:
return (
uchar(*p) == c);
283 if (*p == 0 || *(p+1) == 0)
285 if (*
s != *p)
return NULL;
290 while (++s < ms->src_end) {
292 if (--cont == 0)
return s+1;
294 else if (*
s == b) cont++;
302 const char *p,
const char *ep) {
308 const char *res =
match(ms, (
s+i), ep+1);
317 const char *p,
const char *ep) {
319 const char *res =
match(ms,
s, ep+1);
330 const char *p,
int what) {
332 int level = ms->
level;
358 if ((
size_t)(ms->
src_end-
s) >= len &&
385 const char *ep;
char previous;
389 LUA_QL(
"%%f")
" in pattern");
391 previous = (
s == ms->
src_init) ?
'\0' : *(
s-1);
397 if (isdigit(
uchar(*(p+1)))) {
420 if (m && ((res=
match(ms,
s+1, ep+1)) !=
NULL))
435 s++; p=ep;
goto init;
444static const char *
lmemfind (
const char *s1,
size_t l1,
445 const char *s2,
size_t l2) {
446 if (l2 == 0)
return s1;
447 else if (l2 > l1)
return NULL;
452 while (l1 > 0 && (init = (
const char *)memchr(s1, *s2, l1)) !=
NULL) {
454 if (memcmp(init, s2+1, l2) == 0)
468 if (i >= ms->
level) {
487 int nlevels = (ms->
level == 0 &&
s) ? 1 : ms->
level;
489 for (i = 0; i < nlevels; i++)
500 if (init < 0) init = 0;
501 else if ((
size_t)(init) > l1) init = (ptrdiff_t)l1;
505 const char *s2 =
lmemfind(
s+init, l1-init, p, l2);
514 int anchor = (*p ==
'^') ? (p++, 1) : 0;
515 const char *s1=
s+init;
531 }
while (s1++ < ms.
src_end && !anchor);
564 if (e == src) newstart++;
594 for (i = 0; i < l; i++) {
595 if (news[i] !=
L_ESC)
599 if (!isdigit(
uchar(news[i])))
601 else if (news[i] ==
'0')
650 int anchor = (*p ==
'^') ? (p++, 1) : 0;
656 "string/function/table expected");
664 e =
match(&ms, src, p);
693#define MAX_FORMAT (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
702 case '"':
case '\\':
case '\n': {
726 const char *p = strfrmt;
727 while (*p !=
'\0' && strchr(
FLAGS, *p) !=
NULL) p++;
728 if ((
size_t)(p - strfrmt) >=
sizeof(
FLAGS))
729 luaL_error(L,
"invalid format (repeated flags)");
730 if (isdigit(
uchar(*p))) p++;
731 if (isdigit(
uchar(*p))) p++;
734 if (isdigit(
uchar(*p))) p++;
735 if (isdigit(
uchar(*p))) p++;
737 if (isdigit(
uchar(*p)))
738 luaL_error(L,
"invalid format (width or precision too long)");
740 strncpy(form, strfrmt, p - strfrmt + 1);
741 form += p - strfrmt + 1;
748 size_t l = strlen(form);
749 char spec = form[l - 1];
761 const char *strfrmt_end = strfrmt+sfl;
764 while (strfrmt < strfrmt_end) {
765 if (*strfrmt !=
L_ESC)
767 else if (*++strfrmt ==
L_ESC)
775 switch (*strfrmt++) {
780 case 'd':
case 'i': {
785 case 'o':
case 'u':
case 'x':
case 'X': {
790 case 'e':
case 'E':
case 'f':
791 case 'g':
case 'G': {
802 if (!strchr(form,
'.') && l >= 100) {
810 sprintf(buff, form,
s);
816 LUA_QL(
"format"), *(strfrmt - 1));
864#if defined(LUA_COMPAT_GFIND)
static size_t find(const char *s, const char *pattern, size_t start)
CURL_EXTERN int void * arg
LUA_API void lua_pushcclosure(lua_State *L, lua_CFunction fn, int n)
LUA_API int lua_setmetatable(lua_State *L, int objindex)
LUA_API void lua_pushnil(lua_State *L)
LUA_API int lua_dump(lua_State *L, lua_Writer writer, void *data)
LUA_API void lua_setfield(lua_State *L, int idx, const char *k)
LUA_API int lua_toboolean(lua_State *L, int idx)
LUA_API const char * lua_tolstring(lua_State *L, int idx, size_t *len)
LUA_API void lua_pushvalue(lua_State *L, int idx)
LUA_API int lua_type(lua_State *L, int idx)
LUA_API void lua_gettable(lua_State *L, int idx)
LUA_API void lua_createtable(lua_State *L, int narray, int nrec)
LUA_API int lua_isstring(lua_State *L, int idx)
LUA_API void lua_pushlstring(lua_State *L, const char *s, size_t len)
LUA_API void lua_settop(lua_State *L, int idx)
LUA_API void lua_pushinteger(lua_State *L, lua_Integer n)
LUA_API void lua_getfield(lua_State *L, int idx, const char *k)
LUA_API int lua_gettop(lua_State *L)
LUALIB_API void luaL_buffinit(lua_State *L, luaL_Buffer *B)
LUALIB_API void luaL_addlstring(luaL_Buffer *B, const char *s, size_t l)
LUALIB_API void luaL_checkstack(lua_State *L, int space, const char *mes)
LUALIB_API void luaL_checktype(lua_State *L, int narg, int t)
LUALIB_API void luaL_pushresult(luaL_Buffer *B)
LUALIB_API void luaL_addvalue(luaL_Buffer *B)
LUALIB_API int luaL_error(lua_State *L, const char *fmt,...)
LUALIB_API lua_Integer luaL_checkinteger(lua_State *L, int narg)
LUALIB_API lua_Integer luaL_optinteger(lua_State *L, int narg, lua_Integer def)
LUALIB_API const char * luaL_checklstring(lua_State *L, int narg, size_t *len)
LUALIB_API void luaL_register(lua_State *L, const char *libname, const luaL_Reg *l)
LUALIB_API int luaL_argerror(lua_State *L, int narg, const char *extramsg)
LUALIB_API lua_Number luaL_checknumber(lua_State *L, int narg)
#define luaL_typename(L, i)
#define luaL_addchar(B, c)
#define luaL_optint(L, n, d)
#define luaL_checkstring(L, n)
#define luaL_checkint(L, n)
#define luaL_argcheck(L, cond, numarg, extramsg)
static int singlematch(int c, const char *p, const char *ep)
static int str_sub(lua_State *L)
LUALIB_API int luaopen_string(lua_State *L)
static const char * lmemfind(const char *s1, size_t l1, const char *s2, size_t l2)
static const char * match_capture(MatchState *ms, const char *s, int l)
static int matchbracketclass(int c, const char *p, const char *ec)
static void createmetatable(lua_State *L)
static const char * max_expand(MatchState *ms, const char *s, const char *p, const char *ep)
static void push_onecapture(MatchState *ms, int i, const char *s, const char *e)
static int str_len(lua_State *L)
static int str_find(lua_State *L)
static int str_upper(lua_State *L)
static int str_char(lua_State *L)
static int str_gsub(lua_State *L)
static int match_class(int c, int cl)
static int str_reverse(lua_State *L)
static int str_match(lua_State *L)
static const char * match(MatchState *ms, const char *s, const char *p)
static int capture_to_close(MatchState *ms)
static int str_find_aux(lua_State *L, int find)
static const char * end_capture(MatchState *ms, const char *s, const char *p)
static const char * scanformat(lua_State *L, const char *strfrmt, char *form)
static void addquoted(lua_State *L, luaL_Buffer *b, int arg)
struct MatchState MatchState
static int check_capture(MatchState *ms, int l)
static int gfind_nodef(lua_State *L)
static int str_lower(lua_State *L)
static int gmatch(lua_State *L)
static int gmatch_aux(lua_State *L)
static int str_dump(lua_State *L)
static int str_rep(lua_State *L)
static ptrdiff_t posrelat(ptrdiff_t pos, size_t len)
static int push_captures(MatchState *ms, const char *s, const char *e)
static const char * matchbalance(MatchState *ms, const char *s, const char *p)
static void addintlen(char *form)
static void add_s(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
static void add_value(MatchState *ms, luaL_Buffer *b, const char *s, const char *e)
static int str_format(lua_State *L)
static const char * min_expand(MatchState *ms, const char *s, const char *p, const char *ep)
static int str_byte(lua_State *L)
static int writer(lua_State *L, const void *b, size_t size, void *B)
static const luaL_Reg strlib[]
static const char * classend(MatchState *ms, const char *p)
static const char * start_capture(MatchState *ms, const char *s, const char *p, int what)
#define lua_pushliteral(L, s)
#define lua_upvalueindex(i)
#define lua_tostring(L, i)
#define lua_tointeger(L, i)
#define lua_call(L, n, r)
#define lua_replace(L, idx)
CURL_EXTERN CURLMcode curl_socket_t s
struct MatchState::@54 capture[LUA_MAXCAPTURES]