summaryrefslogtreecommitdiffhomepage
path: root/misc
diff options
context:
space:
mode:
authortylov <[email protected]>2023-08-13 23:15:45 +0200
committertylov <[email protected]>2023-08-13 23:15:45 +0200
commit25dc58db206714dc02c1ae0548f6ba7dd3519d29 (patch)
treedcf65b08300d82c4d6752284d5c0a5a00507f07f /misc
parent8bb2f5618e4cefe668a663936354cf53191f2129 (diff)
downloadSTC-modified-25dc58db206714dc02c1ae0548f6ba7dd3519d29.tar.gz
STC-modified-25dc58db206714dc02c1ae0548f6ba7dd3519d29.zip
API CHANGES:
Changed csview: becomes a null-terminated string view. Added csubview: a null-terminated string view/span, like previous csview. Note that csview works like a csubview, so not much compability issues should arise. However, some functions have changed from _sv suffix to _ss.
Diffstat (limited to 'misc')
-rw-r--r--misc/benchmarks/various/string_bench_STC.cpp32
-rw-r--r--misc/examples/algorithms/forfilter.c12
-rw-r--r--misc/examples/regularexpressions/regex2.c2
-rw-r--r--misc/examples/regularexpressions/regex_match.c4
-rw-r--r--misc/examples/regularexpressions/regex_replace.c6
-rw-r--r--misc/examples/strings/cstr_match.c12
-rw-r--r--misc/examples/strings/replace.c4
-rw-r--r--misc/examples/strings/splitstr.c8
-rw-r--r--misc/examples/strings/sso_substr.c16
-rw-r--r--misc/examples/strings/sview_split.c14
-rw-r--r--misc/examples/strings/utf8replace_c.c4
-rw-r--r--misc/tests/cregex_test.c32
12 files changed, 73 insertions, 73 deletions
diff --git a/misc/benchmarks/various/string_bench_STC.cpp b/misc/benchmarks/various/string_bench_STC.cpp
index a5dfd901..9173d4b6 100644
--- a/misc/benchmarks/various/string_bench_STC.cpp
+++ b/misc/benchmarks/various/string_bench_STC.cpp
@@ -7,16 +7,16 @@
#define i_implement
#include <stc/cstr.h> // string
#define i_implement
-#include <stc/csview.h> // string_view
+#include <stc/csubstr.h> // string_view
#include <stc/algo/raii.h>
#define i_key_str
#include <stc/cvec.h> // vec of cstr with const char* lookup
-#define i_type cvec_sv // override default type name (cvec_csview)
-#define i_key csview
-#define i_cmp csview_cmp
-#include <stc/cvec.h> // cvec_vs: vec of csview
+#define i_type cvec_ss // override default type name (cvec_csubstr)
+#define i_key csubstr
+#define i_cmp csubstr_cmp
+#include <stc/cvec.h> // cvec_vs: vec of csubstr
#define i_key_str
#define i_val size_t
@@ -24,7 +24,7 @@
#define i_key_ssv
#define i_val size_t
-#include <stc/csmap.h> // sorted map of cstr, csview lookup
+#include <stc/csmap.h> // sorted map of cstr, csubstr lookup
#define i_key_str
#define i_val size_t
@@ -32,7 +32,7 @@
#define i_key_ssv
#define i_val size_t
-#include <stc/cmap.h> // unordered map of cstr, csview lookup
+#include <stc/cmap.h> // unordered map of cstr, csubstr lookup
cvec_str read_file(const char* name)
@@ -67,7 +67,7 @@ private:
std::chrono::high_resolution_clock::time_point begin;
};
-void initShortStringVec(cvec_str* vs, cvec_sv* vsv)
+void initShortStringVec(cvec_str* vs, cvec_ss* vsv)
{
cvec_str_drop(vs);
cvec_sv_clear(vsv);
@@ -101,14 +101,14 @@ void initShortStringVec(cvec_str* vs, cvec_sv* vsv)
size_t num = 0;
c_foreach (i, cvec_str, *vs)
{
- cvec_sv_push_back(vsv, cstr_sv(i.ref));
+ cvec_sv_push_back(vsv, cstr_ss(i.ref));
num += cstr_size(i.ref);
}
std::cout << "num strings: " << cvec_sv_size(vsv) << std::endl;
std::cout << "avg str len: " << num / (float)cvec_sv_size(vsv) << std::endl;
}
-void initLongStringVec(cvec_str* vs, cvec_sv* vsv)
+void initLongStringVec(cvec_str* vs, cvec_ss* vsv)
{
cvec_str_drop(vs);
cvec_sv_clear(vsv);
@@ -147,7 +147,7 @@ void initLongStringVec(cvec_str* vs, cvec_sv* vsv)
size_t num = 0;
c_foreach (i, cvec_str, *vs)
{
- cvec_sv_push_back(vsv, cstr_sv(i.ref));
+ cvec_sv_push_back(vsv, cstr_ss(i.ref));
num += cstr_size(i.ref);
}
std::cout << "num strings: " << cvec_sv_size(vsv) << std::endl;
@@ -175,7 +175,7 @@ void initMaps(const cvec_str* vs, csmap_str* mapTrans, csmap_ssv* mapSview,
void benchmark(
const cvec_str* vec_string,
- const cvec_sv* vec_stringview,
+ const cvec_ss* vec_stringview,
const csmap_str* mapTrans,
const csmap_ssv* mapSview,
const cmap_str* unordmapTrans,
@@ -187,7 +187,7 @@ const size_t MAX_LOOP = 2000;
int main(void)
{
c_auto (cvec_str, vec_string)
- c_auto (cvec_sv, vec_stringview)
+ c_auto (cvec_ss, vec_stringview)
c_auto (csmap_str, mapTrans)
c_auto (csmap_ssv, mapSview)
c_auto (cmap_str, unordmapTrans)
@@ -229,7 +229,7 @@ int main(void)
void benchmark(
const cvec_str* vec_string,
- const cvec_sv* vec_stringview,
+ const cvec_ss* vec_stringview,
const csmap_str* mapTrans,
const csmap_ssv* mapSview,
const cmap_str* unordmapTrans,
@@ -258,7 +258,7 @@ void benchmark(
stopwatch.start("Trans Map with string_view");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_foreach (j, cvec_sv, *vec_stringview)
+ c_foreach (j, cvec_ss, *vec_stringview)
{
const csmap_ssv_value* v = csmap_ssv_get(mapSview, *j.ref);
if (v)
@@ -286,7 +286,7 @@ void benchmark(
stopwatch.start("Trans Unord Map with string_view");
for (size_t i = 0; i < MAX_LOOP; ++i)
{
- c_foreach (j, cvec_sv, *vec_stringview)
+ c_foreach (j, cvec_ss, *vec_stringview)
{
const cmap_ssv_value* v = cmap_ssv_get(unordmapSview, *j.ref);
if (v)
diff --git a/misc/examples/algorithms/forfilter.c b/misc/examples/algorithms/forfilter.c
index c1426045..d058660d 100644
--- a/misc/examples/algorithms/forfilter.c
+++ b/misc/examples/algorithms/forfilter.c
@@ -2,7 +2,7 @@
#define i_import
#include <stc/cstr.h>
#define i_implement
-#include <stc/csview.h>
+#include <stc/csubstr.h>
#include <stc/algorithm.h>
#define i_type IVec
@@ -82,7 +82,7 @@ fn main() {
}
*/
#define i_type SVec
-#define i_keyclass csview
+#define i_keyclass csubstr
#include <stc/cstack.h>
void demo3(void)
@@ -94,11 +94,11 @@ void demo3(void)
SVec words_containing_i = {0};
c_forfilter (w, SVec, words,
- csview_contains(*w.ref, "i"))
+ csubstr_contains(*w.ref, "i"))
SVec_push(&words_containing_i, *w.ref);
c_foreach (w, SVec, words_containing_i)
- printf(" %.*s", c_SV(*w.ref));
+ printf(" %.*s", c_SS(*w.ref));
puts("");
c_drop(SVec, &words, &words_containing_i);
@@ -107,10 +107,10 @@ void demo3(void)
void demo4(void)
{
// Keep only uppercase letters and convert them to lowercase:
- csview s = c_sv("ab123cReAghNGnΩoEp"); // Ω = multi-byte
+ csubstr s = c_ss("ab123cReAghNGnΩoEp"); // Ω = multi-byte
cstr out = {0};
- c_forfilter (i, csview, s, utf8_isupper(utf8_peek(i.ref))) {
+ c_forfilter (i, csubstr, s, utf8_isupper(utf8_peek(i.ref))) {
char chr[4];
utf8_encode(chr, utf8_tolower(utf8_peek(i.ref)));
cstr_push(&out, chr);
diff --git a/misc/examples/regularexpressions/regex2.c b/misc/examples/regularexpressions/regex2.c
index a798b1a1..85890070 100644
--- a/misc/examples/regularexpressions/regex2.c
+++ b/misc/examples/regularexpressions/regex2.c
@@ -27,7 +27,7 @@ int main(void)
c_formatch (j, &re, s[i].input) {
c_forrange (k, cregex_captures(&re) + 1)
- printf(" submatch %lld: %.*s\n", k, c_SV(j.match[k]));
+ printf(" submatch %lld: %.*s\n", k, c_SS(j.match[k]));
}
}
cregex_drop(&re);
diff --git a/misc/examples/regularexpressions/regex_match.c b/misc/examples/regularexpressions/regex_match.c
index 11426d2d..6eaea781 100644
--- a/misc/examples/regularexpressions/regex_match.c
+++ b/misc/examples/regularexpressions/regex_match.c
@@ -1,7 +1,7 @@
#define i_import
#include <stc/cregex.h>
#define i_implement
-#include <stc/csview.h>
+#include <stc/csubstr.h>
#define i_key float
#include <stc/cstack.h>
@@ -28,7 +28,7 @@ int main(void)
printf(" %g\n", (double)*i.ref);
// extracts the numbers only to a comma separated string.
- cstr nums = cregex_replace_sv(&re, csview_from(str), " $0,", 0, NULL, CREG_STRIP);
+ cstr nums = cregex_replace_ss(&re, csubstr_from(str), " $0,", 0, NULL, CREG_STRIP);
printf("\n%s\n", cstr_str(&nums));
cstr_drop(&nums);
diff --git a/misc/examples/regularexpressions/regex_replace.c b/misc/examples/regularexpressions/regex_replace.c
index f1ea2711..f5fd8691 100644
--- a/misc/examples/regularexpressions/regex_replace.c
+++ b/misc/examples/regularexpressions/regex_replace.c
@@ -1,8 +1,8 @@
#define i_import
#include <stc/cregex.h>
-#include <stc/csview.h>
+#include <stc/csubstr.h>
-bool add_10_years(int i, csview match, cstr* out) {
+bool add_10_years(int i, csubstr match, cstr* out) {
if (i == 1) { // group 1 matches year
int year;
sscanf(match.str, "%4d", &year); // scan 4 chars only
@@ -47,7 +47,7 @@ int main(void)
printf("euros: %s\n", cstr_str(&str));
/* Strip out everything but the matches */
- cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, CREG_STRIP));
+ cstr_take(&str, cregex_replace_ss(&re, csubstr_from(input), "$3.$2.$1;", 0, NULL, CREG_STRIP));
printf("strip: %s\n", cstr_str(&str));
/* Wrap all words in ${} */
diff --git a/misc/examples/strings/cstr_match.c b/misc/examples/strings/cstr_match.c
index be03e981..3c41bd43 100644
--- a/misc/examples/strings/cstr_match.c
+++ b/misc/examples/strings/cstr_match.c
@@ -1,11 +1,11 @@
#define i_implement
#include <stc/cstr.h>
-#include <stc/csview.h>
+#include <stc/csubstr.h>
#include <stdio.h>
int main(void)
{
- cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG");
+ cstr ss = cstr_from("The quick brown fox jumps over the lazy dog.JPG");
intptr_t pos = cstr_find_at(&ss, 0, "brown");
printf("%" c_ZI " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos);
@@ -16,11 +16,11 @@ int main(void)
printf("ends_with: %d\n", cstr_ends_with(&ss, ".JPG"));
cstr s1 = cstr_lit("hell😀 w😀rl🐨");
- csview ch1 = cstr_u8_chr(&s1, 7);
- csview ch2 = cstr_u8_chr(&s1, 10);
+ csubstr ch1 = cstr_u8_chr(&s1, 7);
+ csubstr ch2 = cstr_u8_chr(&s1, 10);
printf("%s\nsize: %" c_ZI ", %" c_ZI "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1));
- printf("ch1: %.*s\n", c_SV(ch1));
- printf("ch2: %.*s\n", c_SV(ch2));
+ printf("ch1: %.*s\n", c_SS(ch1));
+ printf("ch2: %.*s\n", c_SS(ch2));
c_drop(cstr, &ss, &s1);
}
diff --git a/misc/examples/strings/replace.c b/misc/examples/strings/replace.c
index 59a56bf7..2411f1a7 100644
--- a/misc/examples/strings/replace.c
+++ b/misc/examples/strings/replace.c
@@ -20,13 +20,13 @@ int main(void)
cstr_replace_at(&s, 9, 5, s2); // "this is an example string." (1)
printf("(1) %s\n", cstr_str(&s));
- cstr_replace_at_sv(&s, 19, 6, c_sv(s3+7, 6)); // "this is an example phrase." (2)
+ cstr_replace_at_ss(&s, 19, 6, c_ss(s3+7, 6)); // "this is an example phrase." (2)
printf("(2) %s\n", cstr_str(&s));
cstr_replace_at(&s, 8, 10, "just a"); // "this is just a phrase." (3)
printf("(3) %s\n", cstr_str(&s));
- cstr_replace_at_sv(&s, 8, 6, c_sv("a shorty", 7)); // "this is a short phrase." (4)
+ cstr_replace_at_ss(&s, 8, 6, c_ss("a shorty", 7)); // "this is a short phrase." (4)
printf("(4) %s\n", cstr_str(&s));
cstr_replace_at(&s, 22, 1, "!!!"); // "this is a short phrase!!!" (5)
diff --git a/misc/examples/strings/splitstr.c b/misc/examples/strings/splitstr.c
index ef7ed174..6fa76d34 100644
--- a/misc/examples/strings/splitstr.c
+++ b/misc/examples/strings/splitstr.c
@@ -2,20 +2,20 @@
#define i_import // cstr + utf8 functions
#include <stc/cregex.h>
#define i_implement
-#include <stc/csview.h>
+#include <stc/csubstr.h>
int main(void)
{
- puts("Split with c_fortoken (csview):");
+ puts("Split with c_fortoken (csubstr):");
c_fortoken (i, "Hello World C99!", " ")
- printf("'%.*s'\n", c_SV(i.token));
+ printf("'%.*s'\n", c_SS(i.token));
puts("\nSplit with c_formatch (regex):");
cregex re = cregex_from("[^ ]+");
c_formatch (i, &re, " Hello World C99! ")
- printf("'%.*s'\n", c_SV(i.match[0]));
+ printf("'%.*s'\n", c_SS(i.match[0]));
cregex_drop(&re);
}
diff --git a/misc/examples/strings/sso_substr.c b/misc/examples/strings/sso_substr.c
index 687658df..3c6b1046 100644
--- a/misc/examples/strings/sso_substr.c
+++ b/misc/examples/strings/sso_substr.c
@@ -1,20 +1,20 @@
#define i_implement
#include <stc/cstr.h>
#define i_implement
-#include <stc/csview.h>
+#include <stc/csubstr.h>
int main(void)
{
cstr str = cstr_lit("We think in generalities, but we live in details.");
- csview sv1 = cstr_substr_ex(&str, 3, 5); // "think"
- intptr_t pos = cstr_find(&str, "live"); // position of "live"
- csview sv2 = cstr_substr_ex(&str, pos, 4); // "live"
- csview sv3 = cstr_slice_ex(&str, -8, -1); // "details"
- printf("%.*s, %.*s, %.*s\n", c_SV(sv1), c_SV(sv2), c_SV(sv3));
+ csubstr sv1 = cstr_substr_ex(&str, 3, 5); // "think"
+ intptr_t pos = cstr_find(&str, "live"); // position of "live"
+ csubstr sv2 = cstr_substr_ex(&str, pos, 4); // "live"
+ csubstr sv3 = cstr_slice_ex(&str, -8, -1); // "details"
+ printf("%.*s, %.*s, %.*s\n", c_SS(sv1), c_SS(sv2), c_SS(sv3));
cstr_assign(&str, "apples are green or red");
- cstr s2 = cstr_from_sv(cstr_substr_ex(&str, -3, 3)); // "red"
- cstr s3 = cstr_from_sv(cstr_substr_ex(&str, 0, 6)); // "apples"
+ cstr s2 = cstr_from_ss(cstr_substr_ex(&str, -3, 3)); // "red"
+ cstr s3 = cstr_from_ss(cstr_substr_ex(&str, 0, 6)); // "apples"
printf("%s %s: %d, %d\n", cstr_str(&s2), cstr_str(&s3),
cstr_is_long(&str), cstr_is_long(&s2));
c_drop (cstr, &str, &s2, &s3);
diff --git a/misc/examples/strings/sview_split.c b/misc/examples/strings/sview_split.c
index ac275da0..6abbf5e7 100644
--- a/misc/examples/strings/sview_split.c
+++ b/misc/examples/strings/sview_split.c
@@ -1,20 +1,20 @@
#define i_implement
#include <stc/cstr.h>
#define i_implement
-#include <stc/csview.h>
+#include <stc/csubstr.h>
int main(void)
{
// No memory allocations or string length calculations!
- const csview date = c_sv("2021/03/12");
+ const csubstr date = c_ss("2021/03/12");
intptr_t pos = 0;
- const csview year = csview_token(date, "/", &pos);
- const csview month = csview_token(date, "/", &pos);
- const csview day = csview_token(date, "/", &pos);
+ const csubstr year = csubstr_token(date, "/", &pos);
+ const csubstr month = csubstr_token(date, "/", &pos);
+ const csubstr day = csubstr_token(date, "/", &pos);
- printf("%.*s, %.*s, %.*s\n", c_SV(year), c_SV(month), c_SV(day));
+ printf("%.*s, %.*s, %.*s\n", c_SS(year), c_SS(month), c_SS(day));
- cstr y = cstr_from_sv(year), m = cstr_from_sv(month), d = cstr_from_sv(day);
+ cstr y = cstr_from_ss(year), m = cstr_from_ss(month), d = cstr_from_ss(day);
printf("%s, %s, %s\n", cstr_str(&y), cstr_str(&m), cstr_str(&d));
c_drop(cstr, &y, &m, &d);
}
diff --git a/misc/examples/strings/utf8replace_c.c b/misc/examples/strings/utf8replace_c.c
index 1d54486f..03a0442f 100644
--- a/misc/examples/strings/utf8replace_c.c
+++ b/misc/examples/strings/utf8replace_c.c
@@ -10,12 +10,12 @@ int main(void)
cstr_u8_replace_at(&hello,
cstr_u8_to_pos(&hello, 7),
1,
- c_sv("🐨")
+ c_ss("🐨")
);
printf("%s\n", cstr_str(&hello));
c_foreach (c, cstr, hello)
- printf("%.*s,", c_SV(c.u8.chr));
+ printf("%.*s,", c_SS(c.u8.chr));
cstr str = cstr_lit("scooby, dooby doo");
cstr_replace(&str, "oo", "00");
diff --git a/misc/tests/cregex_test.c b/misc/tests/cregex_test.c
index 4e192de6..7cd03930 100644
--- a/misc/tests/cregex_test.c
+++ b/misc/tests/cregex_test.c
@@ -1,6 +1,6 @@
#define i_import
#include <stc/cregex.h>
-#include <stc/csview.h>
+#include <stc/csubstr.h>
#include <stc/algo/raii.h>
#include "ctest.h"
@@ -14,7 +14,7 @@ CTEST(cregex, compile_match_char)
cregex re = cregex_from("äsdf");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
ASSERT_EQ(cregex_find(&re, inp="äsdf", &match, CREG_FULLMATCH), CREG_OK);
ASSERT_EQ(M_START(match), 0);
ASSERT_EQ(M_END(match), 5); // ä is two bytes wide
@@ -32,7 +32,7 @@ CTEST(cregex, compile_match_anchors)
cregex re = cregex_from(inp="^äs.f$");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
ASSERT_EQ(cregex_find(&re, inp="äsdf", &match), CREG_OK);
ASSERT_EQ(M_START(match), 0);
ASSERT_EQ(M_END(match), 5);
@@ -50,7 +50,7 @@ CTEST(cregex, compile_match_quantifiers1)
re = cregex_from("ä+");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
ASSERT_EQ(cregex_find(&re, inp="ääb", &match), CREG_OK);
ASSERT_EQ(M_START(match), 0);
ASSERT_EQ(M_END(match), 4);
@@ -70,7 +70,7 @@ CTEST(cregex, compile_match_quantifiers2)
re = cregex_from("bä*");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
ASSERT_EQ(cregex_find(&re, inp="bääb", &match), CREG_OK);
ASSERT_EQ(M_START(match), 0);
ASSERT_EQ(M_END(match), 5);
@@ -90,7 +90,7 @@ CTEST(cregex, compile_match_escaped_chars)
cregex re = cregex_from("\\n\\r\\t\\{");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
ASSERT_EQ(cregex_find(&re, "\n\r\t{", &match), CREG_OK);
ASSERT_EQ(cregex_find(&re, "\n\r\t", &match), CREG_NOMATCH);
@@ -108,7 +108,7 @@ CTEST(cregex, compile_match_class_simple)
re3 = cregex_from("\\D");
ASSERT_EQ(re3.error, 0);
- csview match;
+ csubstr match;
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);
@@ -129,7 +129,7 @@ CTEST(cregex, compile_match_or)
re = cregex_from("as|df");
ASSERT_EQ(re.error, 0);
- csview match[4];
+ csubstr match[4];
ASSERT_EQ(cregex_find(&re, "as", match), CREG_OK);
ASSERT_EQ(cregex_find(&re, "df", match), CREG_OK);
@@ -146,7 +146,7 @@ CTEST(cregex, compile_match_class_complex_0)
cregex re = cregex_from("[asdf]");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
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);
@@ -160,7 +160,7 @@ CTEST(cregex, compile_match_class_complex_1)
cregex re = cregex_from("[a-zä0-9öA-Z]");
ASSERT_EQ(re.error, 0);
- csview match;
+ csubstr match;
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);
@@ -175,7 +175,7 @@ CTEST(cregex, compile_match_cap)
cregex re = cregex_from("(abc)d");
ASSERT_EQ(re.error, 0);
- csview match[4];
+ csubstr match[4];
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);
@@ -189,7 +189,7 @@ CTEST(cregex, search_all)
c_auto (cregex, re)
{
re = cregex_from("ab");
- csview m = {0};
+ csubstr m = {0};
int res;
ASSERT_EQ(re.error, CREG_OK);
inp="ab,ab,ab";
@@ -220,9 +220,9 @@ CTEST(cregex, captures_cap)
re = cregex_from("(ab)((cd)+)");
ASSERT_EQ(cregex_captures(&re), 3);
- csview cap[5];
+ csubstr cap[5];
ASSERT_EQ(cregex_find(&re, inp="xxabcdcde", cap), CREG_OK);
- ASSERT_TRUE(csview_equals(cap[0], "abcdcd"));
+ ASSERT_TRUE(csubstr_equals(cap[0], "abcdcd"));
ASSERT_EQ(M_END(cap[0]), 8);
ASSERT_EQ(M_START(cap[1]), 2);
@@ -235,7 +235,7 @@ CTEST(cregex, captures_cap)
}
}
-static bool add_10_years(int i, csview match, cstr* out) {
+static bool add_10_years(int i, csubstr match, cstr* out) {
if (i == 1) { // group 1 matches year
int year;
sscanf(match.str, "%4d", &year); // scan 4 chars only
@@ -280,7 +280,7 @@ CTEST(cregex, replace)
ASSERT_STREQ(cstr_str(&str), "start date: 31.12.2015, end date: 28.02.2022");
// Strip out everything but the matches
- cstr_take(&str, cregex_replace_sv(&re, csview_from(input), "$3.$2.$1;", 0, NULL, CREG_STRIP));
+ cstr_take(&str, cregex_replace_ss(&re, csubstr_from(input), "$3.$2.$1;", 0, NULL, CREG_STRIP));
ASSERT_STREQ(cstr_str(&str), "31.12.2015;28.02.2022;");
}
}