summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorShmuel Zeigerman <solomuz0@gmail.com>2012-02-13 14:42:31 +0200
committerShmuel Zeigerman <solomuz0@gmail.com>2012-02-13 14:42:31 +0200
commit94b08ae226ca1e2ccb4c88ab51d2679b858d646e (patch)
tree5a6ce5ab7f67727dc7f8e5eea24543a45037de82
parent9a4df7ffa58f90a802b9ce5704cb2452cb54fc9e (diff)
downloadlrexlib-94b08ae226ca1e2ccb4c88ab51d2679b858d646e.tar.gz
Removed function plainfind.
-rw-r--r--doc/manual.txt39
-rw-r--r--src/algo.h49
-rw-r--r--src/common.c10
-rw-r--r--src/gnu/lgnu.c1
-rw-r--r--src/oniguruma/lonig.c1
-rw-r--r--src/pcre/lpcre.c1
-rw-r--r--src/posix/lposix.c1
-rw-r--r--src/tre/Makefile1
-rw-r--r--src/tre/ltre.c1
-rw-r--r--test/common_sets.lua23
-rw-r--r--test/tre_sets.lua23
-rw-r--r--windows/mingw/rex_tre.mak2
12 files changed, 8 insertions, 144 deletions
diff --git a/doc/manual.txt b/doc/manual.txt
index d6bedf8..1b5ea53 100644
--- a/doc/manual.txt
+++ b/doc/manual.txt
@@ -829,45 +829,6 @@ This function returns a string containing the version of the used TRE library.
------------------------------------------------------------
-Other functions
-~~~~~~~~~~~~~~~
-
-plainfind
----------
-
-:funcdef:`rex.plainfind (subj, patt, [init], [ci])`
-
-The function searches for the first match of the string *patt* in the subject
-*subj*, starting from offset *init*.
-
- * The string *patt* is not regular expression, all its characters stand for
- themselves.
- * Both strings *subj* and *patt* can have embedded zeros.
- * The flag *ci* specifies case-insensitive search (current locale is used).
- * This function uses no regex library.
-
- +---------+---------------------------+--------+-------------+
- |Parameter| Description | Type |Default Value|
- +=========+===========================+========+=============+
- | subj |subject | string | n/a |
- +---------+---------------------------+--------+-------------+
- | patt |text to find | string | n/a |
- +---------+---------------------------+--------+-------------+
- | [init] |start offset in the subject| number | 1 |
- | |(can be negative) | | |
- +---------+---------------------------+--------+-------------+
- | [ci] |case insensitive search |boolean | ``false`` |
- +---------+---------------------------+--------+-------------+
-
-**Returns on success:**
- 1. The start point of the match (a number).
- 2. The end point of the match (a number).
-
-**Returns on failure:**
- 1. ``nil``
-
-------------------------------------------------------------
-
Incompatibilities with previous versions
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
diff --git a/src/algo.h b/src/algo.h
index d5ad9d7..f196372 100644
--- a/src/algo.h
+++ b/src/algo.h
@@ -659,52 +659,3 @@ static int ud_tfind (lua_State *L) {
static int ud_exec (lua_State *L) {
return generic_find_method (L, METHOD_EXEC);
}
-
-
-/* function plainfind (s, p, [st], [ci]) */
-/* (optimized for performance at the expense of code size) */
-static int plainfind_func (lua_State *L) {
- size_t textlen, patlen;
- const char *text = luaL_checklstring (L, 1, &textlen);
- const char *pattern = luaL_checklstring (L, 2, &patlen);
- const char *from = text + get_startoffset (L, 3, textlen);
- int ci = lua_toboolean (L, 4);
- const char *end = text + textlen - patlen;
-
- if (patlen == 0 && from <= end)
- goto found;
- if (ci ) {
- for (; from <= end; ++from) {
- if (toupper(*from) == toupper(*pattern)) {
- const char *f = from, *p = pattern;
- size_t len = patlen;
- while (--len) {
- if (toupper (*++f) != toupper (*++p))
- break;
- }
- if (len == 0)
- goto found;
- }
- }
- }
- else {
- for (; from <= end; ++from) {
- if (*from == *pattern) {
- const char *f = from, *p = pattern;
- size_t len = patlen;
- while (--len) {
- if (*++f != *++p)
- break;
- }
- if (len == 0)
- goto found;
- }
- }
- }
- lua_pushnil (L);
- return 1;
-found:
- lua_pushinteger (L, from - text + 1);
- lua_pushinteger (L, from - text + patlen);
- return 2;
-}
diff --git a/src/common.c b/src/common.c
index 03a2f1d..09d595c 100644
--- a/src/common.c
+++ b/src/common.c
@@ -203,7 +203,7 @@ void bufferZ_putrepstring (TBuffer *BufRep, int reppos, int nsub) {
if (isdigit (*q)) {
int num;
*dbuf = *q;
- num = atoi (dbuf);
+ num = strtol (dbuf, NULL, 10);
if (num == 1 && nsub == 0)
num = 0;
else if (num > nsub) {
@@ -220,12 +220,13 @@ void bufferZ_putrepstring (TBuffer *BufRep, int reppos, int nsub) {
}
}
+#ifdef WIDE_CHAR_GSUB
/* 1. When called repeatedly on the same TBuffer, its existing data
is discarded and overwritten by the new data.
2. The TBuffer's array is never shrunk by this function.
*/
void bufferZ_putrepstringW (TBuffer *BufRep, int reppos, int nsub) {
- char dbuf[] = { 0, 0 };
+ wchar_t dbuf[] = { 0, 0 };
size_t replen;
const wchar_t *p = (const wchar_t*) lua_tolstring (BufRep->L, reppos, &replen);
replen /= sizeof(wchar_t);
@@ -241,8 +242,8 @@ void bufferZ_putrepstringW (TBuffer *BufRep, int reppos, int nsub) {
if (++q < end) { /* skip % */
if (iswdigit (*q)) {
int num;
- *dbuf = *q & 0xFF;
- num = atoi (dbuf);
+ *dbuf = *q;
+ num = wcstol (dbuf, NULL, 10);
if (num == 1 && nsub == 0)
num = 0;
else if (num > nsub) {
@@ -258,6 +259,7 @@ void bufferZ_putrepstringW (TBuffer *BufRep, int reppos, int nsub) {
else break;
}
}
+#endif
/******************************************************************************
The intended use of this function is as follows:
diff --git a/src/gnu/lgnu.c b/src/gnu/lgnu.c
index 07e8e3c..9f12a81 100644
--- a/src/gnu/lgnu.c
+++ b/src/gnu/lgnu.c
@@ -300,7 +300,6 @@ static const luaL_Reg rexlib[] = {
{ "split", split },
{ "new", ud_new },
{ "flags", Gnu_get_flags },
- { "plainfind", plainfind_func },
{ NULL, NULL }
};
diff --git a/src/oniguruma/lonig.c b/src/oniguruma/lonig.c
index d3cdfcc..08f1b59 100644
--- a/src/oniguruma/lonig.c
+++ b/src/oniguruma/lonig.c
@@ -331,7 +331,6 @@ static const luaL_Reg rexlib[] = {
{ "gsub", gsub },
{ "split", split },
{ "new", ud_new },
- { "plainfind", plainfind_func },
{ "flags", LOnig_get_flags },
{ "version", LOnig_version },
{ "setdefaultsyntax", LOnig_setdefaultsyntax },
diff --git a/src/pcre/lpcre.c b/src/pcre/lpcre.c
index 107e83d..266ba94 100644
--- a/src/pcre/lpcre.c
+++ b/src/pcre/lpcre.c
@@ -388,7 +388,6 @@ static const luaL_Reg rexlib[] = {
{ "gsub", gsub },
{ "split", split },
{ "new", ud_new },
- { "plainfind", plainfind_func },
{ "flags", Lpcre_get_flags },
{ "version", Lpcre_version },
{ "maketables", Lpcre_maketables },
diff --git a/src/posix/lposix.c b/src/posix/lposix.c
index 189a36b..86ab3f3 100644
--- a/src/posix/lposix.c
+++ b/src/posix/lposix.c
@@ -271,7 +271,6 @@ static const luaL_Reg rexlib[] = {
{ "split", split },
{ "new", ud_new },
{ "flags", Posix_get_flags },
- { "plainfind", plainfind_func },
{ NULL, NULL }
};
diff --git a/src/tre/Makefile b/src/tre/Makefile
index 2d3964e..2350108 100644
--- a/src/tre/Makefile
+++ b/src/tre/Makefile
@@ -26,6 +26,7 @@ REGNAME = tre
# === END OF USER SETTINGS ===
OBJ = ltre.o ltre_w.o ../common.o
+MYCFLAGS = -DWIDE_CHAR_GSUB
include ../common.mak
diff --git a/src/tre/ltre.c b/src/tre/ltre.c
index c612183..6033a55 100644
--- a/src/tre/ltre.c
+++ b/src/tre/ltre.c
@@ -332,7 +332,6 @@ static const luaL_Reg rexlib[] = {
{ "split", split },
{ "new", ud_new },
{ "flags", Ltre_get_flags },
- { "plainfind", plainfind_func },
{ "config", Ltre_config },
{ "version", Ltre_version },
{ NULL, NULL }
diff --git a/test/common_sets.lua b/test/common_sets.lua
index 406d8fa..8489030 100644
--- a/test/common_sets.lua
+++ b/test/common_sets.lua
@@ -155,28 +155,6 @@ local function set_m_match (lib, flg)
}
end
-local function set_f_plainfind (lib, flg)
- return {
- Name = "Function plainfind",
- Func = lib.plainfind,
- --{ subj, patt, st, ci } { results }
- { {"abcd", "bc"}, {2,3} }, -- [none]
- { {"abcd", "dc"}, {N} }, -- [none]
- { {"abcd", "cd"}, {3,4} }, -- positive st
- { {"abcd", "cd", 3}, {3,4} }, -- positive st
- { {"abcd", "cd", 4}, {N} }, -- failing st
- { {"abcd", "bc", 2}, {2,3} }, -- positive st
- { {"abcd", "bc", -4}, {2,3} }, -- negative st
- { {"abcd", "bc", 3}, {N} }, -- failing st
- { {"abcd", "BC"}, {N} }, -- case sensitive
- { {"abcd", "BC", N, true}, {2,3} }, -- case insensitive
- { {"ab\0cd", "b\0c"}, {2,4} }, -- contains nul
- { {"abcd", "", 1}, {1,0} }, -- empty pattern
- { {"abcd", "", 5}, {5,4} }, -- empty pattern
- { {"abcd", "", 6}, {N} }, -- empty pattern
- }
-end
-
local function set_f_gsub1 (lib, flg)
local subj, pat = "abcdef", "[abef]+"
local cpat = lib.new(pat)
@@ -337,6 +315,5 @@ return function (libname)
set_f_gsub5 (lib),
set_f_gsub6 (lib),
set_f_gsub8 (lib),
- set_f_plainfind (lib),
}
end
diff --git a/test/tre_sets.lua b/test/tre_sets.lua
index b2169a1..89f00b6 100644
--- a/test/tre_sets.lua
+++ b/test/tre_sets.lua
@@ -157,28 +157,6 @@ local function set_m_wmatch (lib, flg)
}
end
-local function set_f_plainfind (lib, flg)
- return {
- Name = "Function plainfind",
- Func = lib.plainfind,
- --{ subj, patt, st, ci } { results }
- { {"abcd", "bc"}, {2,3} }, -- [none]
- { {"abcd", "dc"}, {N} }, -- [none]
- { {"abcd", "cd"}, {3,4} }, -- positive st
- { {"abcd", "cd", 3}, {3,4} }, -- positive st
- { {"abcd", "cd", 4}, {N} }, -- failing st
- { {"abcd", "bc", 2}, {2,3} }, -- positive st
- { {"abcd", "bc", -4}, {2,3} }, -- negative st
- { {"abcd", "bc", 3}, {N} }, -- failing st
- { {"abcd", "BC"}, {N} }, -- case sensitive
- { {"abcd", "BC", N, true}, {2,3} }, -- case insensitive
- { {"ab\0cd", "b\0c"}, {2,4} }, -- contains nul
- { {"abcd", "", 1}, {1,0} }, -- empty pattern
- { {"abcd", "", 5}, {5,4} }, -- empty pattern
- { {"abcd", "", 6}, {N} }, -- empty pattern
- }
-end
-
local function set_f_wgsub1 (lib, flg)
local subj, pat = L"abcdef", L"[abef]+"
local cpat = lib.wnew(pat)
@@ -340,6 +318,5 @@ return function (libname)
set_f_wgsub5 (lib),
set_f_wgsub6 (lib),
set_f_wgsub8 (lib),
- --set_f_plainfind (lib),
}
end
diff --git a/windows/mingw/rex_tre.mak b/windows/mingw/rex_tre.mak
index c1c31ea..14507a6 100644
--- a/windows/mingw/rex_tre.mak
+++ b/windows/mingw/rex_tre.mak
@@ -9,7 +9,7 @@ PROJECT = rex_tre
MYINCS = -I$(REGEXINC) -I$(LUAINC)
MYLIBS = -L$(DLLPATH) -ltre -l$(LUADLL)
OBJ = ltre.o ltre_w.o common.o
-MYCFLAGS = -W -Wall -O2
+MYCFLAGS = -W -Wall -O2 -DWIDE_CHAR_GSUB
EXPORTED = 'luaopen_$(PROJECT)'
SRCPATH = ..\..\src;..\..\src\tre
TESTPATH = ..\..\test