summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-06-12 18:51:24 +0200
committerTyge Løvset <[email protected]>2022-06-12 18:51:24 +0200
commit2e289403cdeb998a38fd9467f05e9e8525cb69e7 (patch)
treebf48c7bc93faf4db7b8adb9f71db92fbd8fb9e33
parent69e930f36ab18999009d064f08e2a0b4f10733b3 (diff)
downloadSTC-modified-2e289403cdeb998a38fd9467f05e9e8525cb69e7.tar.gz
STC-modified-2e289403cdeb998a38fd9467f05e9e8525cb69e7.zip
Renamed cregex_find89 => cregex_match()
-rw-r--r--examples/regex1.c2
-rw-r--r--examples/regex2.c2
-rw-r--r--examples/regex_match.c6
-rw-r--r--include/stc/cregex.h10
-rw-r--r--src/cregex.c8
-rw-r--r--tests/cregex_test.c110
6 files changed, 69 insertions, 69 deletions
diff --git a/examples/regex1.c b/examples/regex1.c
index f2623f7a..09e4299d 100644
--- a/examples/regex1.c
+++ b/examples/regex1.c
@@ -21,7 +21,7 @@ int main(int argc, char* argv[])
if (cstr_equals(input, "q"))
break;
- if (cregex_find(&float_expr, cstr_str(&input), 0, NULL, 0) > 0)
+ if (cregex_match(&float_expr, cstr_str(&input), 0, NULL, 0) > 0)
printf("Input is a float\n");
else
printf("Invalid input : Not a float\n");
diff --git a/examples/regex2.c b/examples/regex2.c
index 41266b65..82247da5 100644
--- a/examples/regex2.c
+++ b/examples/regex2.c
@@ -20,7 +20,7 @@ int main()
}
cregmatch m[20];
printf("input: %s\n", inputs[i]);
- if (cregex_find(&re, inputs[i], 20, m, 0) > 0)
+ if (cregex_match(&re, inputs[i], 20, m, 0) > 0)
{
c_forrange (j, cregex_captures(re))
{
diff --git a/examples/regex_match.c b/examples/regex_match.c
index 05161b90..2b135bb7 100644
--- a/examples/regex_match.c
+++ b/examples/regex_match.c
@@ -14,20 +14,20 @@ int main()
int res = cregex_compile(&re, "[+-]?([0-9]*\\.)?\\d+([Ee][+-]?\\d+)?", 0);
printf("%d\n", res);
cregmatch m[10];
- if (cregex_find(&re, s, 10, m, 0) > 0) {
+ if (cregex_match(&re, s, 10, m, 0) > 0) {
printf("Found digits at position %" PRIuMAX "-%" PRIuMAX "\n", m[0].str - s, m[0].str - s + m[0].size);
} else {
printf("Could not find any digits\n");
}
- while (cregex_find(&re, s, 10, m, creg_next) > 0) {
+ while (cregex_match(&re, s, 10, m, creg_next) > 0) {
printf("%" c_PRIsv " ; ", c_ARGsv(m[0]));
}
puts("");
res = cregex_compile(&re, "(.+)\\b(.+)", 0);
printf("groups: %d\n", res);
- if ((res = cregex_find(&re, "hello@wørld", 10, m, 0)) > 0) {
+ if ((res = cregex_match(&re, "hello@wørld", 10, m, 0)) > 0) {
c_forrange (i, res)
printf("match: [%" c_PRIsv "]\n", c_ARGsv(m[i]));
} else
diff --git a/include/stc/cregex.h b/include/stc/cregex.h
index 1afe484f..448f9405 100644
--- a/include/stc/cregex.h
+++ b/include/stc/cregex.h
@@ -23,10 +23,10 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
-#ifndef CREGEX9_H_
-#define CREGEX9_H_
+#ifndef CREGEX_H_
+#define CREGEX_H_
/*
- * cregex9.h
+ * cregex.h
*
* This is a extended version of regexp9, supporting UTF8 input, common
* shorthand character classes, ++.
@@ -79,8 +79,8 @@ int cregex_compile(cregex *self, const char* pattern, int cflags);
int cregex_captures(cregex rx);
/* return number of capture groups on success, or (negative) error code on failure. */
-int cregex_find(const cregex *self, const char* string,
- size_t nmatch, cregmatch match[], int mflags);
+int cregex_match(const cregex *self, const char* string,
+ size_t nmatch, cregmatch match[], int mflags);
void cregex_replace(const char* src, char* dst, int dsize,
int nmatch, const cregmatch match[]);
diff --git a/src/cregex.c b/src/cregex.c
index 69fc6cbb..8ec56fae 100644
--- a/src/cregex.c
+++ b/src/cregex.c
@@ -1104,7 +1104,7 @@ regexec2(const Reprog *progp, /* program to run */
}
static int
-regexec9(const Reprog *progp, /* program to run */
+regexec(const Reprog *progp, /* program to run */
const char *bol, /* string to run machine on */
int ms, /* number of elements at mp */
Resub mp[], /* subexpression elements */
@@ -1215,9 +1215,9 @@ int cregex_captures(cregex rx) {
return rx.prog ? 1 + rx.prog->nsubids : 0;
}
-int cregex_find(const cregex *rx, const char* string,
- size_t nmatch, cregmatch match[], int mflags) {
- int res = regexec9(rx->prog, string, nmatch, match, mflags);
+int cregex_match(const cregex *rx, const char* string,
+ size_t nmatch, cregmatch match[], int mflags) {
+ int res = regexec(rx->prog, string, nmatch, match, mflags);
switch (res) {
case 1: return 1 + rx->prog->nsubids;
case 0: return creg_nomatch;
diff --git a/tests/cregex_test.c b/tests/cregex_test.c
index 03b3d7ea..e6166a10 100644
--- a/tests/cregex_test.c
+++ b/tests/cregex_test.c
@@ -23,15 +23,15 @@ START_TEST(compile_match_char)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "äsdf", &match));
+ ck_assert(cregex_match(&re, "äsdf", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 5); // ä is two bytes wide
- ck_assert(cregex_find(&re, "zäsdf", &match));
+ ck_assert(cregex_match(&re, "zäsdf", &match));
ck_assert_uint_eq(match.start, 1);
ck_assert_uint_eq(match.end, 6);
- ck_assert(cregex_find(&re, "äsdf", &match));
+ ck_assert(cregex_match(&re, "äsdf", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 5);
@@ -45,12 +45,12 @@ START_TEST(compile_match_anchors)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(re, "äsdf", &match));
+ ck_assert(cregex_match(re, "äsdf", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 5);
- ck_assert(cregex_find(re, "äs♥f", &match));
- ck_assert(cregex_find(re, "äsöf", &match));
+ ck_assert(cregex_match(re, "äs♥f", &match));
+ ck_assert(cregex_match(re, "äsöf", &match));
cregex_drop(re);
}
@@ -63,30 +63,30 @@ START_TEST(compile_match_quantifiers)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "ääb", &match));
+ ck_assert(cregex_match(&re, "ääb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 4);
- ck_assert(cregex_find(&re, "bäbb", &match));
+ ck_assert(cregex_match(&re, "bäbb", &match));
ck_assert_uint_eq(match.start, 1);
ck_assert_uint_eq(match.end, 3);
- ck_assert(!cregex_find(&re, "bbb", &match));
+ ck_assert(!cregex_match(&re, "bbb", &match));
}
c_auto (cregex, re) {
re = cregex_new("bä*");
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "bääb", &match));
+ ck_assert(cregex_match(&re, "bääb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 5);
- ck_assert(cregex_find(&re, "bäbb", &match));
+ ck_assert(cregex_match(&re, "bäbb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 3);
- ck_assert(cregex_find(&re, "bbb", &match));
+ ck_assert(cregex_match(&re, "bbb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 1);
}
@@ -110,27 +110,27 @@ START_TEST(compile_match_complex_quants)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re1, "ääb", &match));
+ ck_assert(cregex_match(&re1, "ääb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 4);
- ck_assert(cregex_find(&re1, "äääb", &match));
- ck_assert(cregex_find(&re1, "äb", &match));
- ck_assert(!cregex_find(&re1, "b", &match));
+ ck_assert(cregex_match(&re1, "äääb", &match));
+ ck_assert(cregex_match(&re1, "äb", &match));
+ ck_assert(!cregex_match(&re1, "b", &match));
- ck_assert(cregex_find(&re2, "ää", &match));
+ ck_assert(cregex_match(&re2, "ää", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 2);
- ck_assert(cregex_find(&re2, "bbäb", &match));
- ck_assert(!cregex_find(&re2, "bbbb", &match));
+ ck_assert(cregex_match(&re2, "bbäb", &match));
+ ck_assert(!cregex_match(&re2, "bbbb", &match));
- ck_assert(cregex_find(&re3, "ääääääääääb", &match));
+ ck_assert(cregex_match(&re3, "ääääääääääb", &match));
ck_assert_uint_eq(match.start, 0);
ck_assert_uint_eq(match.end, 20);
- ck_assert(cregex_find(&re3, "b", &match));
+ ck_assert(cregex_match(&re3, "b", &match));
- ck_assert(cregex_find(&re4, "bä", &match));
- ck_assert(cregex_find(&re4, "bää", &match));
- ck_assert(cregex_find(&re4, "bäää", &match));
+ ck_assert(cregex_match(&re4, "bä", &match));
+ ck_assert(cregex_match(&re4, "bää", &match));
+ ck_assert(cregex_match(&re4, "bäää", &match));
}
}
END_TEST
@@ -141,8 +141,8 @@ START_TEST(compile_match_escaped_chars)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "\n\r\t{", &match));
- ck_assert(!cregex_find(&re, "\n\r\t", &match));
+ ck_assert(cregex_match(&re, "\n\r\t{", &match));
+ ck_assert(!cregex_match(&re, "\n\r\t", &match));
cregex_drop(&re);
}
@@ -160,16 +160,16 @@ START_TEST(compile_match_class_simple)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re1, " ", &match));
- ck_assert(cregex_find(&re1, "\r", &match));
- ck_assert(cregex_find(&re1, "\n", &match));
+ ck_assert(cregex_match(&re1, " ", &match));
+ ck_assert(cregex_match(&re1, "\r", &match));
+ ck_assert(cregex_match(&re1, "\n", &match));
- ck_assert(cregex_find(&re2, "a", &match));
- ck_assert(cregex_find(&re2, "0", &match));
- ck_assert(cregex_find(&re2, "_", &match));
+ ck_assert(cregex_match(&re2, "a", &match));
+ ck_assert(cregex_match(&re2, "0", &match));
+ ck_assert(cregex_match(&re2, "_", &match));
- ck_assert(cregex_find(&re3, "k", &match));
- ck_assert(!cregex_find(&re3, "0", &match));
+ ck_assert(cregex_match(&re3, "k", &match));
+ ck_assert(!cregex_match(&re3, "0", &match));
}
}
END_TEST
@@ -182,14 +182,14 @@ START_TEST(compile_match_or)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "as", &match));
- ck_assert(cregex_find(&re, "df", &match));
+ ck_assert(cregex_match(&re, "as", &match));
+ ck_assert(cregex_match(&re, "df", &match));
re2 = cregex_new("(as|df)");
ck_assert_int_eq(cregex_error(), cregex_OK);
- ck_assert(cregex_find(&re2, "as", &match));
- ck_assert(cregex_find(&re2, "df", &match));
+ ck_assert(cregex_match(&re2, "as", &match));
+ ck_assert(cregex_match(&re2, "df", &match));
}
}
END_TEST
@@ -200,10 +200,10 @@ START_TEST(compile_match_class_complex_0)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "a", &match));
- ck_assert(cregex_find(&re, "s", &match));
- ck_assert(cregex_find(&re, "d", &match));
- ck_assert(cregex_find(&re, "f", &match));
+ ck_assert(cregex_match(&re, "a", &match));
+ ck_assert(cregex_match(&re, "s", &match));
+ ck_assert(cregex_match(&re, "d", &match));
+ ck_assert(cregex_match(&re, "f", &match));
cregex_drop(&re);
}
@@ -215,11 +215,11 @@ START_TEST(compile_match_class_complex_1)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "a", &match));
- ck_assert(cregex_find(&re, "5", &match));
- ck_assert(cregex_find(&re, "A", &match));
- ck_assert(cregex_find(&re, "ä", &match));
- ck_assert(cregex_find(&re, "ö", &match));
+ ck_assert(cregex_match(&re, "a", &match));
+ ck_assert(cregex_match(&re, "5", &match));
+ ck_assert(cregex_match(&re, "A", &match));
+ ck_assert(cregex_match(&re, "ä", &match));
+ ck_assert(cregex_match(&re, "ö", &match));
cregex_drop(&re);
}
@@ -231,9 +231,9 @@ START_TEST(compile_match_cap)
ck_assert_int_eq(cregex_error(), cregex_OK);
cregex_match match;
- ck_assert(cregex_find(&re, "abcd", &match));
- ck_assert(cregex_find(&re, "llljabcdkk", &match));
- ck_assert(!cregex_find(&re, "abc", &match));
+ ck_assert(cregex_match(&re, "abcd", &match));
+ ck_assert(cregex_match(&re, "llljabcdkk", &match));
+ ck_assert(!cregex_match(&re, "abc", &match));
cregex_drop(&re);
}
@@ -266,13 +266,13 @@ START_TEST(search_all)
cregex_match m = {0};
bool res;
- res = cregex_find_next(&re, "ab,ab,ab", &m);
+ res = cregex_match_next(&re, "ab,ab,ab", &m);
ck_assert(res && m.start == 0);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
+ res = cregex_match_next(&re, "ab,ab,ab", &m);
ck_assert(res && m.start == 3);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
+ res = cregex_match_next(&re, "ab,ab,ab", &m);
ck_assert(res && m.start == 6);
- res = cregex_find_next(&re, "ab,ab,ab", &m);
+ res = cregex_match_next(&re, "ab,ab,ab", &m);
ck_assert(!res);
}
}
@@ -294,7 +294,7 @@ START_TEST(captures_cap)
ck_assert_uint_eq(cregex_capture_size(re), 3);
cregex_match match;
- ck_assert(cregex_find(&re, "xxabcdcde", &match));
+ ck_assert(cregex_match(&re, "xxabcdcde", &match));
cregex_match cap0, cap1, cap2;
cregex_capture(&re, 0, &cap0);