From c787dccd9b5c3e55547a2c4bb598c0276de65034 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 16 Aug 1999 17:52:00 -0300 Subject: "const" !!! --- lstrlib.c | 91 +++++++++++++++++++++++++++++++++------------------------------ 1 file changed, 47 insertions(+), 44 deletions(-) (limited to 'lstrlib.c') diff --git a/lstrlib.c b/lstrlib.c index a91f1a40..057605b3 100644 --- a/lstrlib.c +++ b/lstrlib.c @@ -1,5 +1,5 @@ /* -** $Id: lstrlib.c,v 1.32 1999/06/17 17:04:03 roberto Exp roberto $ +** $Id: lstrlib.c,v 1.33 1999/08/10 12:55:56 roberto Exp roberto $ ** Standard library for strings and pattern-matching ** See Copyright Notice in lua.h */ @@ -16,16 +16,14 @@ -static void addnchar (char *s, int n) -{ +static void addnchar (const char *s, int n) { char *b = luaL_openspace(n); memcpy(b, s, n); luaL_addsize(n); } -static void str_len (void) -{ +static void str_len (void) { long l; luaL_check_lstr(1, &l); lua_pushnumber(l); @@ -45,7 +43,7 @@ static long posrelat (long pos, long len) { static void str_sub (void) { long l; - char *s = luaL_check_lstr(1, &l); + const char *s = luaL_check_lstr(1, &l); long start = posrelat(luaL_check_long(2), l); long end = posrelat(luaL_opt_long(3, -1), l); if (start < 1) start = 1; @@ -59,7 +57,7 @@ static void str_sub (void) { static void str_lower (void) { long l; int i; - char *s = luaL_check_lstr(1, &l); + const char *s = luaL_check_lstr(1, &l); luaL_resetbuffer(); for (i=0; i 0) @@ -91,7 +88,7 @@ static void str_rep (void) static void str_byte (void) { long l; - char *s = luaL_check_lstr(1, &l); + const char *s = luaL_check_lstr(1, &l); long pos = posrelat(luaL_opt_long(2, 1), l); luaL_arg_check(0src_end && luaI_singlematch((unsigned char)*(s+i), p, ep)) i++; /* keeps trying to match mith the maximum repetitions */ while (i>=0) { - char *res = match((s+i), ep+1, cap); + const char *res = match((s+i), ep+1, cap); if (res) return res; i--; /* else didn't match; reduce 1 repetition to try again */ } @@ -275,9 +274,10 @@ static char *max_expand (char *s, char *p, char *ep, struct Capture *cap) { } -static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) { +static const char *min_expand (const char *s, const char *p, const char *ep, + struct Capture *cap) { for (;;) { - char *res = match(s, ep+1, cap); + const char *res = match(s, ep+1, cap); if (res != NULL) return res; else if (ssrc_end && luaI_singlematch((unsigned char)*s, p, ep)) @@ -287,8 +287,9 @@ static char *min_expand (char *s, char *p, char *ep, struct Capture *cap) { } -static char *start_capt (char *s, char *p, struct Capture *cap) { - char *res; +static const char *start_capt (const char *s, const char *p, + struct Capture *cap) { + const char *res; int level = cap->level; if (level >= MAX_CAPT) lua_error("too many captures"); cap->capture[level].init = s; @@ -300,9 +301,10 @@ static char *start_capt (char *s, char *p, struct Capture *cap) { } -static char *end_capt (char *s, char *p, struct Capture *cap) { +static const char *end_capt (const char *s, const char *p, + struct Capture *cap) { int l = capture_to_close(cap); - char *res; + const char *res; cap->capture[l].len = s - cap->capture[l].init; /* close capture */ if ((res = match(s, p+1, cap)) == NULL) /* match failed? */ cap->capture[l].len = -1; /* undo capture */ @@ -310,7 +312,8 @@ static char *end_capt (char *s, char *p, struct Capture *cap) { } -static char *match_capture (char *s, int level, struct Capture *cap) { +static const char *match_capture (const char *s, int level, + struct Capture *cap) { int l = check_cap(level, cap); int len = cap->capture[l].len; if (cap->src_end-s >= len && @@ -320,7 +323,7 @@ static char *match_capture (char *s, int level, struct Capture *cap) { } -static char *match (char *s, char *p, struct Capture *cap) { +static const char *match (const char *s, const char *p, struct Capture *cap) { init: /* using goto's to optimize tail recursion */ switch (*p) { case '(': /* start capture */ @@ -346,11 +349,11 @@ static char *match (char *s, char *p, struct Capture *cap) { return (s == cap->src_end) ? s : NULL; /* check end of string */ else goto dflt; default: dflt: { /* it is a pattern item */ - char *ep = luaI_classend(p); /* points to what is next */ + const char *ep = luaI_classend(p); /* points to what is next */ int m = ssrc_end && luaI_singlematch((unsigned char)*s, p, ep); switch (*ep) { case '?': { /* optional */ - char *res; + const char *res; if (m && ((res=match(s+1, ep+1, cap)) != NULL)) return res; p=ep+1; goto init; /* else return match(s, ep+1, cap); */ @@ -372,8 +375,8 @@ static char *match (char *s, char *p, struct Capture *cap) { static void str_find (void) { long l; - char *s = luaL_check_lstr(1, &l); - char *p = luaL_check_string(2); + const char *s = luaL_check_lstr(1, &l); + const char *p = luaL_check_string(2); long init = posrelat(luaL_opt_long(3, 1), l) - 1; struct Capture cap; luaL_arg_check(0 <= init && init <= l, 3, "out of range"); @@ -388,10 +391,10 @@ static void str_find (void) { } else { int anchor = (*p == '^') ? (p++, 1) : 0; - char *s1=s+init; + const char *s1=s+init; cap.src_end = s+l; do { - char *res; + const char *res; cap.level = 0; if ((res=match(s1, p, &cap)) != NULL) { lua_pushnumber(s1-s+1); /* start */ @@ -407,7 +410,7 @@ static void str_find (void) { static void add_s (lua_Object newp, struct Capture *cap) { if (lua_isstring(newp)) { - char *news = lua_getstring(newp); + const char *news = lua_getstring(newp); int l = lua_strlen(newp); int i; for (i=0; i= 100) { /* no precision and string is too big to be formatted; keep original string */ @@ -570,7 +573,7 @@ static void str_format (void) { } -static struct luaL_reg strlib[] = { +static const struct luaL_reg strlib[] = { {"strlen", str_len}, {"strsub", str_sub}, {"strlower", str_lower}, -- cgit v1.2.3-55-g6feb