Browse Source

singlematch and item_end are used by "read", in iolib.

v5-2
Roberto Ierusalimschy 29 years ago
parent
commit
25b6dae7c0
  1. 5
      lualib.h
  2. 14
      strlib.c

5
lualib.h

@ -2,7 +2,7 @@
** Libraries to be used in LUA programs ** Libraries to be used in LUA programs
** Grupo de Tecnologia em Computacao Grafica ** Grupo de Tecnologia em Computacao Grafica
** TeCGraf - PUC-Rio ** TeCGraf - PUC-Rio
** $Id: lualib.h,v 1.8 1996/04/30 21:13:55 roberto Exp roberto $ ** $Id: lualib.h,v 1.9 1996/08/01 14:55:33 roberto Exp roberto $
*/ */
#ifndef lualib_h #ifndef lualib_h
@ -31,5 +31,8 @@ long lua_opt_number (int numArg, long def, char *funcname);
char *luaI_addchar (int c); char *luaI_addchar (int c);
void luaI_addquoted (char *s); void luaI_addquoted (char *s);
char *item_end (char *p);
int singlematch (int c, char *p);
#endif #endif

14
strlib.c

@ -3,7 +3,7 @@
** String library to LUA ** String library to LUA
*/ */
char *rcs_strlib="$Id: strlib.c,v 1.24 1996/05/22 21:59:07 roberto Exp roberto $"; char *rcs_strlib="$Id: strlib.c,v 1.25 1996/08/01 14:55:33 roberto Exp roberto $";
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
@ -178,7 +178,7 @@ static void str_ascii (void)
#define ESC '%' #define ESC '%'
#define SPECIALS "^$*?.([%" #define SPECIALS "^$*?.([%"
static char *item_end (char *p) char *item_end (char *p)
{ {
switch (*p) { switch (*p) {
case '\0': return p; case '\0': return p;
@ -212,9 +212,9 @@ static int matchclass (int c, int cl)
return (islower(cl) ? res : !res); return (islower(cl) ? res : !res);
} }
static int singlematch (int c, char *p) int singlematch (int c, char *p)
{ {
if (c == 0) return 0; if (c <= 0) return 0; /* \0, EOF or other strange flags */
switch (*p) { switch (*p) {
case '.': return 1; case '.': return 1;
case ESC: return matchclass(c, *(p+1)); case ESC: return matchclass(c, *(p+1));
@ -323,13 +323,13 @@ static char *match (char *s, char *p, int level)
int m = singlematch(*s, p); int m = singlematch(*s, p);
char *ep = item_end(p); /* get what is next */ char *ep = item_end(p); /* get what is next */
switch (*ep) { switch (*ep) {
case '*': { /* repetition? */ case '*': { /* repetition */
char *res; char *res;
if (m && (res = match(s+1, p, level))) if (m && (res = match(s+1, p, level)))
return res; return res;
p=ep+1; goto init; /* else return match(s, ep+1, level); */ p=ep+1; goto init; /* else return match(s, ep+1, level); */
} }
case '?': { /* optional? */ case '?': { /* optional */
char *res; char *res;
if (m && (res = match(s+1, ep+1, level))) if (m && (res = match(s+1, ep+1, level)))
return res; return res;
@ -487,7 +487,7 @@ static struct lua_reg strlib[] = {
{"ascii", str_ascii}, {"ascii", str_ascii},
{"format", str_format}, {"format", str_format},
{"strfind", str_find}, {"strfind", str_find},
{"s", str_s} {"gsub", str_s}
}; };

Loading…
Cancel
Save