diff options
-rwxr-xr-x | ChangeLog | 4 | ||||
-rwxr-xr-x | doc/manual.txt | 43 | ||||
-rwxr-xr-x | src/lpcre.c | 64 |
3 files changed, 29 insertions, 82 deletions
@@ -1,3 +1,7 @@ +2007-05-03 Shmuel Zeigerman <shmuz@actcom.co.il> + + * lpcre.c (settables): removed API function. + 2007-05-02 Shmuel Zeigerman <shmuz@actcom.co.il> * algo_t.h: new file added, for making struct definitions visible to diff --git a/doc/manual.txt b/doc/manual.txt index 0b71419..3ae9e33 100755 --- a/doc/manual.txt +++ b/doc/manual.txt @@ -84,10 +84,8 @@ Notes 7. Parameter *locale* (*lo*) can be either a string (e.g., "French_France.1252"), or a userdata obtained from a call to maketables_. The default value that - Lrexlib uses when the parameter is not supplied or ``nil``, is: - - * the built-in PCRE set of character tables - when Lrexlib is loaded. - * determined by the last call to settables_. + Lrexlib uses when the parameter is not supplied or ``nil`` is the built-in + PCRE set of character tables - when Lrexlib is loaded. ------------------------------------------------------------ @@ -569,41 +567,8 @@ maketables :funcdef:`rex.maketables ()` Creates a table set corresponding to the current active locale and returns it as -a userdata. The returned value can be passed to the function settables_ and to -any Lrexlib function accepting the *locale* parameter. - ------------------------------------------------------------- - -settables ---------- - -[PCRE only] - -:funcdef:`rex.settables ([tables])` - -This function replaces the default set of character tables, by the one supplied -in the parameter *tables*. - -The *tables* parameter should be either a userdata, obtained from a call to -maketables_, or ``nil``. In the latter case, the built-in PCRE set of tables -becomes the default. - -Lrexlib maintains one "default" set of character tables, in addition to the set -built-in into PCRE. When a Lrexlib function accepting the *locale* argument is -called with that argument omitted, then the default set of character tables is -used. - -The initial default set of tables is the built-in PCRE set. - - +---------+--------------------------------+--------+-------------+ - |Parameter| Description | Type |Default Value| - +=========+================================+========+=============+ - |[tables] |See the above description. |userdata| ``nil`` | - | | | | | - +---------+--------------------------------+--------+-------------+ - -**Returns:** - The old value of the default set (``nil`` for the built-in PCRE set). +a userdata. The returned value can be passed to any Lrexlib function accepting +the *locale* parameter. ------------------------------------------------------------ diff --git a/src/lpcre.c b/src/lpcre.c index da08372..9a56faa 100755 --- a/src/lpcre.c +++ b/src/lpcre.c @@ -82,7 +82,6 @@ const char pcre_typename[] = REX_LIBNAME"_regex"; #define INDEX_CHARTABLES_META 1 /* chartables type's metatable */ #define INDEX_CHARTABLES_LINK 2 /* link chartables to compiled regex */ -const unsigned char *DefaultTables; const char chartables_typename[] = "chartables"; /* Functions @@ -95,21 +94,28 @@ static void push_chartables_meta (lua_State *L) { } static int getcflags (lua_State *L, int pos) { - if (LUA_TSTRING == lua_type (L, pos)) { - const char *s = lua_tostring (L, pos); - int res = 0, ch; - while ((ch = *s++) != '\0') { - if (ch == 'i') res |= PCRE_CASELESS; - else if (ch == 'm') res |= PCRE_MULTILINE; - else if (ch == 's') res |= PCRE_DOTALL; - else if (ch == 'x') res |= PCRE_EXTENDED; - else if (ch == 'U') res |= PCRE_UNGREEDY; - else if (ch == 'X') res |= PCRE_EXTRA; + switch (lua_type (L, pos)) { + case LUA_TNONE: + case LUA_TNIL: + return ALG_CFLAGS_DFLT; + case LUA_TNUMBER: + return lua_tointeger (L, pos); + case LUA_TSTRING: { + const char *s = lua_tostring (L, pos); + int res = 0, ch; + while ((ch = *s++) != '\0') { + if (ch == 'i') res |= PCRE_CASELESS; + else if (ch == 'm') res |= PCRE_MULTILINE; + else if (ch == 's') res |= PCRE_DOTALL; + else if (ch == 'x') res |= PCRE_EXTENDED; + else if (ch == 'U') res |= PCRE_UNGREEDY; + else if (ch == 'X') res |= PCRE_EXTRA; + } + return res; } - return res; + default: + return luaL_argerror (L, pos, "number or string expected"); } - else - return luaL_optint (L, pos, ALG_CFLAGS_DFLT); } static int generate_error (lua_State *L, const TPcre *ud, int errcode) { @@ -155,33 +161,6 @@ static void **check_tables (lua_State *L, int pos) { return NULL; } -/* function settables ([tables]) */ -/* Create tables for the current active locale and set them as the default - * tables, instead of the PCRE built-in tables. - * For proper clean-up, create a chartables userdata, and put it into the - * chartables' metatable at a constant key. - */ -static int Lpcre_settables (lua_State *L) -{ - lua_settop (L, 1); - if (!lua_toboolean (L, 1)) { - DefaultTables = NULL; /* use the built-in tables */ - lua_pushnil (L); - } - else { - DefaultTables = *check_tables (L, 1); - } - /* get old value (to be returned) */ - push_chartables_meta (L); - lua_pushlightuserdata (L, &DefaultTables); - lua_rawget (L, -2); - /* set new value */ - lua_pushlightuserdata (L, &DefaultTables); - lua_pushvalue (L, 1); - lua_rawset (L, -4); - return 1; -} - static int tables_gc (lua_State *L) { void **ud = check_tables (L, 1); if (*ud) { @@ -240,7 +219,7 @@ static int compile_regex (lua_State *L, const TArgComp *argC, TPcre **pud) { lua_pop (L, 1); } else - tables = DefaultTables; + tables = NULL; ud->pr = pcre_compile (argC->pattern, argC->cflags, &error, &erroffset, tables); if (!ud->pr) @@ -425,7 +404,6 @@ static const luaL_reg rexlib[] = { { "plainfind", plainfind_func }, { "flags", Lpcre_get_flags }, { "version", Lpcre_version }, - { "settables", Lpcre_settables }, { "maketables", Lpcre_maketables }, #if PCRE_MAJOR >= 4 { "config", Lpcre_config }, |