misc/liblua/lstrlib.c
changeset 10017 de822cd3df3a
parent 3697 d5b30d6373fc
equal deleted inserted replaced
10015:4feced261c68 10017:de822cd3df3a
   162 ** PATTERN MATCHING
   162 ** PATTERN MATCHING
   163 ** =======================================================
   163 ** =======================================================
   164 */
   164 */
   165 
   165 
   166 
   166 
   167 #define CAP_UNFINISHED	(-1)
   167 #define CAP_UNFINISHED  (-1)
   168 #define CAP_POSITION	(-2)
   168 #define CAP_POSITION    (-2)
   169 
   169 
   170 typedef struct MatchState {
   170 typedef struct MatchState {
   171   const char *src_init;  /* init of source string */
   171   const char *src_init;  /* init of source string */
   172   const char *src_end;  /* end (`\0') of source string */
   172   const char *src_end;  /* end (`\0') of source string */
   173   lua_State *L;
   173   lua_State *L;
   177     ptrdiff_t len;
   177     ptrdiff_t len;
   178   } capture[LUA_MAXCAPTURES];
   178   } capture[LUA_MAXCAPTURES];
   179 } MatchState;
   179 } MatchState;
   180 
   180 
   181 
   181 
   182 #define L_ESC		'%'
   182 #define L_ESC       '%'
   183 #define SPECIALS	"^$*+?.([%-"
   183 #define SPECIALS    "^$*+?.([%-"
   184 
   184 
   185 
   185 
   186 static int check_capture (MatchState *ms, int l) {
   186 static int check_capture (MatchState *ms, int l) {
   187   l -= '1';
   187   l -= '1';
   188   if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
   188   if (l < 0 || l >= ms->level || ms->capture[l].len == CAP_UNFINISHED)
   681 
   681 
   682 /* }====================================================== */
   682 /* }====================================================== */
   683 
   683 
   684 
   684 
   685 /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
   685 /* maximum size of each formatted item (> len(format('%99.99f', -1e308))) */
   686 #define MAX_ITEM	512
   686 #define MAX_ITEM    512
   687 /* valid flags in a format specification */
   687 /* valid flags in a format specification */
   688 #define FLAGS	"-+ #0"
   688 #define FLAGS   "-+ #0"
   689 /*
   689 /*
   690 ** maximum size of each format specification (such as '%-099.99d')
   690 ** maximum size of each format specification (such as '%-099.99d')
   691 ** (+10 accounts for %99.99x plus margin of error)
   691 ** (+10 accounts for %99.99x plus margin of error)
   692 */
   692 */
   693 #define MAX_FORMAT	(sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
   693 #define MAX_FORMAT  (sizeof(FLAGS) + sizeof(LUA_INTFRMLEN) + 10)
   694 
   694 
   695 
   695 
   696 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
   696 static void addquoted (lua_State *L, luaL_Buffer *b, int arg) {
   697   size_t l;
   697   size_t l;
   698   const char *s = luaL_checklstring(L, arg, &l);
   698   const char *s = luaL_checklstring(L, arg, &l);