summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples')
-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
10 files changed, 41 insertions, 41 deletions
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");