diff options
| -rw-r--r-- | docs/cspan_api.md | 12 | ||||
| -rw-r--r-- | include/stc/cspan.h | 12 | ||||
| -rw-r--r-- | misc/examples/csmap_find.c | 6 | ||||
| -rw-r--r-- | misc/examples/multidim.c | 2 | ||||
| -rw-r--r-- | misc/examples/printspan.c | 2 | ||||
| -rw-r--r-- | misc/tests/cregex_test.c | 108 |
6 files changed, 71 insertions, 71 deletions
diff --git a/docs/cspan_api.md b/docs/cspan_api.md index 6da2acca..d1532d7b 100644 --- a/docs/cspan_api.md +++ b/docs/cspan_api.md @@ -10,12 +10,12 @@ See the c++ classes [std::span](https://en.cppreference.com/w/cpp/container/span ```c #include <stc/cspan.h> -using_cspan(SpanType, ValueType, Rank); // define SpanType with ValueType elements. - // Rank is number of dimensions (max 4) +use_cspan(SpanType, ValueType, Rank); // define SpanType with ValueType elements. + // Rank is number of dimensions (max 4) // Shorthands: -using_cspan2(S, ValueType); // define span types S, S2 with ranks 1, 2. -using_cspan3(S, ValueType); // define span types S, S2, S3 with ranks 1, 2, 3. -using_cspan4(S, ValueType); // define span types S, S2, S3, S4 with ranks 1, 2, 3, 4. +use_cspan2(S, ValueType); // define span types S, S2 with ranks 1, 2. +use_cspan3(S, ValueType); // define span types S, S2, S3 with ranks 1, 2, 3. +use_cspan4(S, ValueType); // define span types S, S2, S3, S4 with ranks 1, 2, 3, 4. ``` ## Methods Note that `cspan_multidim()`, `cmake_from*()`, `cspan_atN()`, `and cspan_subspanN()` require a (safe) cast to its span-type @@ -66,7 +66,7 @@ void SpanType_next(SpanTypeN_iter* it); #define i_val float #include <stc/cstack.h> -using_cspan3(Span, float); // Shorthand to define span types Span, Span2, and Span3. +use_cspan3(Span, float); // Shorthand to define span types Span, Span2, and Span3. int main() { diff --git a/include/stc/cspan.h b/include/stc/cspan.h index 5b0358e2..03307288 100644 --- a/include/stc/cspan.h +++ b/include/stc/cspan.h @@ -25,8 +25,8 @@ #include <stdio.h> #include <stc/cspan.h> #include <stc/algo/filter.h> -using_cspan(Span2f, float, 2); -using_cspan(Intspan, int, 1); +use_cspan(Span2f, float, 2); +use_cspan(Intspan, int, 1); int demo1() { float raw[4*5]; @@ -60,7 +60,7 @@ int demo2() { #include "ccommon.h" -#define using_cspan(Self, T, RANK) \ +#define use_cspan(Self, T, RANK) \ typedef T Self##_value; typedef T Self##_raw; \ typedef struct { Self##_value *ref, *end; } Self##_iter; \ typedef struct { Self##_value *data; uint32_t dim[RANK]; } Self; \ @@ -81,9 +81,9 @@ int demo2() { { if (++it->ref == it->end) it->ref = NULL; } \ struct stc_nostruct -#define using_cspan2(Self, T) using_cspan(Self, T, 1); using_cspan(Self##2, T, 2) -#define using_cspan3(Self, T) using_cspan2(Self, T); using_cspan(Self##3, T, 3) -#define using_cspan4(Self, T) using_cspan3(Self, T); using_cspan(Self##4, T, 4) +#define use_cspan2(Self, T) use_cspan(Self, T, 1); use_cspan(Self##2, T, 2) +#define use_cspan3(Self, T) use_cspan2(Self, T); use_cspan(Self##3, T, 3) +#define use_cspan4(Self, T) use_cspan3(Self, T); use_cspan(Self##4, T, 4) #define cspan_rank_ok(self, rank) c_static_assert(cspan_rank(self) == rank) diff --git a/misc/examples/csmap_find.c b/misc/examples/csmap_find.c index a61a47be..a94348f8 100644 --- a/misc/examples/csmap_find.c +++ b/misc/examples/csmap_find.c @@ -16,7 +16,7 @@ void print_elem(csmap_istr_raw p) { printf("(%d, %s) ", p.first, p.second); } -#define using_print_collection(CX) \ +#define use_print_collection(CX) \ void print_collection_##CX(const CX* t) { \ printf("%" c_ZU " elements: ", CX##_size(t)); \ \ @@ -26,8 +26,8 @@ void print_elem(csmap_istr_raw p) { puts(""); \ } -using_print_collection(csmap_istr) -using_print_collection(cvec_istr) +use_print_collection(csmap_istr) +use_print_collection(cvec_istr) void findit(csmap_istr c, csmap_istr_key val) { diff --git a/misc/examples/multidim.c b/misc/examples/multidim.c index 8a5492dc..37360516 100644 --- a/misc/examples/multidim.c +++ b/misc/examples/multidim.c @@ -4,7 +4,7 @@ #include <stc/cspan.h> #include <stdio.h> -using_cspan3(ispan, int); +use_cspan3(ispan, int); int main() { diff --git a/misc/examples/printspan.c b/misc/examples/printspan.c index 82b54367..a27d8bbd 100644 --- a/misc/examples/printspan.c +++ b/misc/examples/printspan.c @@ -12,7 +12,7 @@ #include <stc/cset.h> #include <stc/cspan.h> -using_cspan(intspan, int, 1); +use_cspan(intspan, int, 1); void printMe(intspan container) { printf("%d:", (int)cspan_size(&container)); diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c index bd13d16a..24c39950 100644 --- a/misc/tests/cregex_test.c +++ b/misc/tests/cregex_test.c @@ -10,7 +10,7 @@ CTEST(cregex, compile_match_char) { const char* inp; - cregex re = cregex_from("äsdf", 0); + cregex re = cregex_from("äsdf"); ASSERT_EQ(re.error, 0); csview match; @@ -18,7 +18,7 @@ CTEST(cregex, compile_match_char) ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 5); // ä is two bytes wide - ASSERT_EQ(cregex_find(&re, inp="zäsdf", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="zäsdf", &match), CREG_OK); ASSERT_EQ(M_START(match), 1); ASSERT_EQ(M_END(match), 6); @@ -28,11 +28,11 @@ CTEST(cregex, compile_match_char) CTEST(cregex, compile_match_anchors) { const char* inp; - cregex re = cregex_from(inp="^äs.f$", 0); + cregex re = cregex_from(inp="^äs.f$"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, inp="äsdf", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="äsdf", &match), CREG_OK); ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 5); @@ -46,19 +46,19 @@ CTEST(cregex, compile_match_quantifiers1) { const char* inp; c_AUTO (cregex, re) { - re = cregex_from("ä+", 0); + re = cregex_from("ä+"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, inp="ääb", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="ääb", &match), CREG_OK); ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 4); - ASSERT_EQ(cregex_find(&re, inp="bäbb", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="bäbb", &match), CREG_OK); ASSERT_EQ(M_START(match), 1); ASSERT_EQ(M_END(match), 3); - ASSERT_EQ(cregex_find(&re, "bbb", &match, 0), CREG_NOMATCH); + ASSERT_EQ(cregex_find(&re, "bbb", &match), CREG_NOMATCH); } } @@ -66,19 +66,19 @@ CTEST(cregex, compile_match_quantifiers2) { const char* inp; c_AUTO (cregex, re) { - re = cregex_from("bä*", 0); + re = cregex_from("bä*"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, inp="bääb", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="bääb", &match), CREG_OK); ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 5); - ASSERT_EQ(cregex_find(&re, inp="bäbb", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="bäbb", &match), CREG_OK); ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 3); - ASSERT_EQ(cregex_find(&re, inp="bbb", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="bbb", &match), CREG_OK); ASSERT_EQ(M_START(match), 0); ASSERT_EQ(M_END(match), 1); } @@ -86,12 +86,12 @@ CTEST(cregex, compile_match_quantifiers2) CTEST(cregex, compile_match_escaped_chars) { - cregex re = cregex_from("\\n\\r\\t\\{", 0); + cregex re = cregex_from("\\n\\r\\t\\{"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, "\n\r\t{", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "\n\r\t", &match, 0), CREG_NOMATCH); + ASSERT_EQ(cregex_find(&re, "\n\r\t{", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "\n\r\t", &match), CREG_NOMATCH); cregex_drop(&re); } @@ -100,24 +100,24 @@ CTEST(cregex, compile_match_class_simple) { c_AUTO (cregex, re1, re2, re3) { - re1 = cregex_from("\\s", 0); + re1 = cregex_from("\\s"); ASSERT_EQ(re1.error, 0); - re2 = cregex_from("\\w", 0); + re2 = cregex_from("\\w"); ASSERT_EQ(re2.error, 0); - re3 = cregex_from("\\D", 0); + re3 = cregex_from("\\D"); ASSERT_EQ(re3.error, 0); csview match; - ASSERT_EQ(cregex_find(&re1, " " , &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re1, "\r", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re1, "\n", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re1, " " , &match), CREG_OK); + ASSERT_EQ(cregex_find(&re1, "\r", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re1, "\n", &match), CREG_OK); - ASSERT_EQ(cregex_find(&re2, "a", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re2, "0", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re2, "_", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re2, "a", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re2, "0", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re2, "_", &match), CREG_OK); - ASSERT_EQ(cregex_find(&re3, "k", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re3, "0", &match, 0), CREG_NOMATCH); + ASSERT_EQ(cregex_find(&re3, "k", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re3, "0", &match), CREG_NOMATCH); } } @@ -125,59 +125,59 @@ CTEST(cregex, compile_match_or) { c_AUTO (cregex, re, re2) { - re = cregex_from("as|df", 0); + re = cregex_from("as|df"); ASSERT_EQ(re.error, 0); csview match[4]; - ASSERT_EQ(cregex_find(&re, "as", match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "df", match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, "as", match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "df", match), CREG_OK); - re2 = cregex_from("(as|df)", 0); + re2 = cregex_from("(as|df)"); ASSERT_EQ(re2.error, 0); - ASSERT_EQ(cregex_find(&re2, "as", match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re2, "df", match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re2, "as", match), CREG_OK); + ASSERT_EQ(cregex_find(&re2, "df", match), CREG_OK); } } CTEST(cregex, compile_match_class_complex_0) { - cregex re = cregex_from("[asdf]", 0); + cregex re = cregex_from("[asdf]"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, "a", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "s", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "d", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "f", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, "a", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "s", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "d", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "f", &match), CREG_OK); cregex_drop(&re); } CTEST(cregex, compile_match_class_complex_1) { - cregex re = cregex_from("[a-zä0-9öA-Z]", 0); + cregex re = cregex_from("[a-zä0-9öA-Z]"); ASSERT_EQ(re.error, 0); csview match; - ASSERT_EQ(cregex_find(&re, "a", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "5", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "A", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "ä", &match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "ö", &match, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, "a", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "5", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "A", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "ä", &match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "ö", &match), CREG_OK); cregex_drop(&re); } CTEST(cregex, compile_match_cap) { - cregex re = cregex_from("(abc)d", 0); + cregex re = cregex_from("(abc)d"); ASSERT_EQ(re.error, 0); csview match[4]; - ASSERT_EQ(cregex_find(&re, "abcd", match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "llljabcdkk", match, 0), CREG_OK); - ASSERT_EQ(cregex_find(&re, "abc", match, 0), CREG_NOMATCH); + ASSERT_EQ(cregex_find(&re, "abcd", match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "llljabcdkk", match), CREG_OK); + ASSERT_EQ(cregex_find(&re, "abc", match), CREG_NOMATCH); cregex_drop(&re); } @@ -187,7 +187,7 @@ CTEST(cregex, search_all) const char* inp; c_AUTO (cregex, re) { - re = cregex_from("ab", 0); + re = cregex_from("ab"); csview m = {0}; int res; ASSERT_EQ(re.error, CREG_OK); @@ -207,7 +207,7 @@ CTEST(cregex, search_all) CTEST(cregex, captures_len) { c_AUTO (cregex, re) { - cregex re = cregex_from("(ab(cd))(ef)", 0); + cregex re = cregex_from("(ab(cd))(ef)"); ASSERT_EQ(cregex_captures(&re), 4); } } @@ -216,11 +216,11 @@ CTEST(cregex, captures_cap) { const char* inp; c_AUTO (cregex, re) { - re = cregex_from("(ab)((cd)+)", 0); + re = cregex_from("(ab)((cd)+)"); ASSERT_EQ(cregex_captures(&re), 4); csview cap[5]; - ASSERT_EQ(cregex_find(&re, inp="xxabcdcde", cap, 0), CREG_OK); + ASSERT_EQ(cregex_find(&re, inp="xxabcdcde", cap), CREG_OK); ASSERT_TRUE(csview_equals(cap[0], "abcdcd")); ASSERT_EQ(M_END(cap[0]), 8); @@ -255,11 +255,11 @@ CTEST(cregex, replace) ASSERT_TRUE(cstr_equals(&str, "start date: YYYY-MM-DD, end date: YYYY-MM-DD")); /* US date format, and add 10 years to dates: */ - cstr_take(&str, cregex_replace_pattern_ex(pattern, input, "$1/$3/$2", 0, add_10_years, CREG_DEFAULT)); + cstr_take(&str, cregex_replace_pattern(pattern, input, "$1/$3/$2", 0, add_10_years, CREG_DEFAULT)); ASSERT_TRUE(cstr_equals(&str, "start date: 2025/31/12, end date: 2032/28/02")); /* Wrap first date inside []: */ - cstr_take(&str, cregex_replace_pattern_ex(pattern, input, "[$0]", 1, NULL, CREG_DEFAULT)); + cstr_take(&str, cregex_replace_pattern(pattern, input, "[$0]", 1)); ASSERT_TRUE(cstr_equals(&str, "start date: [2015-12-31], end date: 2022-02-28")); /* Wrap all words in ${} */ @@ -267,7 +267,7 @@ CTEST(cregex, replace) ASSERT_TRUE(cstr_equals(&str, "52 ${apples} ${and} 31 ${mangoes}")); /* Compile RE separately */ - c_WITH (cregex re = cregex_from(pattern, CREG_DEFAULT), cregex_drop(&re)) { + c_WITH (cregex re = cregex_from(pattern), cregex_drop(&re)) { ASSERT_EQ(cregex_captures(&re), 4); /* European date format. */ |
