summaryrefslogtreecommitdiffhomepage
path: root/misc/examples
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2022-12-29 00:28:50 +0100
committerTyge Løvset <[email protected]>2022-12-29 00:28:50 +0100
commit0761c13f316cc98ae7756f3527931aa86bed5016 (patch)
treee90777558956fcf91d6b1c958e0c3a6fb0ab007f /misc/examples
parentd623c6c85071b9af5d607bb5d9aceceaea05220a (diff)
downloadSTC-modified-0761c13f316cc98ae7756f3527931aa86bed5016.tar.gz
STC-modified-0761c13f316cc98ae7756f3527931aa86bed5016.zip
Restructuring of some headers into include/algo folder. Some API changes *_replace*() functions have been renamed, and a few minor API changes.
Diffstat (limited to 'misc/examples')
-rw-r--r--misc/examples/cpque.c2
-rw-r--r--misc/examples/demos.c2
-rw-r--r--misc/examples/forfilter.c8
-rw-r--r--misc/examples/forloops.c2
-rw-r--r--misc/examples/prime.c6
-rw-r--r--misc/examples/regex_replace.c4
-rw-r--r--misc/examples/utf8replace_c.c4
7 files changed, 16 insertions, 12 deletions
diff --git a/misc/examples/cpque.c b/misc/examples/cpque.c
index 47080038..2ec841ae 100644
--- a/misc/examples/cpque.c
+++ b/misc/examples/cpque.c
@@ -8,7 +8,7 @@
#include <stdio.h>
#include <stdbool.h>
#include <stc/forward.h>
-#include <stc/views.h>
+#include <stc/algo/crange.h>
#include <stc/cstr.h>
// predeclare
diff --git a/misc/examples/demos.c b/misc/examples/demos.c
index b077aa73..4a9fac89 100644
--- a/misc/examples/demos.c
+++ b/misc/examples/demos.c
@@ -13,7 +13,7 @@ void stringdemo1()
cstr_erase(&cs, 7, 5); // -nine
printf("%s.\n", cstr_str(&cs));
- cstr_replace(&cs, "seven", "four", 1);
+ cstr_replace_ex(&cs, "seven", "four", 1);
printf("%s.\n", cstr_str(&cs));
cstr_take(&cs, cstr_from_fmt("%s *** %s", cstr_str(&cs), cstr_str(&cs)));
diff --git a/misc/examples/forfilter.c b/misc/examples/forfilter.c
index 32154904..c0a4ccad 100644
--- a/misc/examples/forfilter.c
+++ b/misc/examples/forfilter.c
@@ -2,7 +2,8 @@
#define i_extern
#include <stc/cstr.h>
#include <stc/csview.h>
-#include <stc/views.h>
+#include <stc/algo/filter.h>
+#include <stc/algo/crange.h>
#define i_type IVec
#define i_val int
@@ -63,12 +64,13 @@ void demo2(void)
c_AUTO (IVec, vector) {
puts("demo2:");
- c_FORFILTER (x, crange, crange_literal(INT64_MAX)
+ c_FORFILTER (x, crange, crange_LITERAL(INT64_MAX)
, c_FLT_SKIPWHILE(x, *x.ref != 11)
&& *x.ref % 2 != 0
, c_FLT_TAKE(x, 5))
IVec_push(&vector, *x.ref * *x.ref);
- c_FOREACH (x, IVec, vector) printf(" %d", *x.ref);
+ c_FOREACH (x, IVec, vector)
+ printf(" %d", *x.ref);
puts("");
}
}
diff --git a/misc/examples/forloops.c b/misc/examples/forloops.c
index 95a955a3..69c1c193 100644
--- a/misc/examples/forloops.c
+++ b/misc/examples/forloops.c
@@ -1,5 +1,5 @@
#include <stdio.h>
-#include <stc/views.h>
+#include <stc/algo/filter.h>
#define i_type IVec
#define i_val int
diff --git a/misc/examples/prime.c b/misc/examples/prime.c
index 41d637b8..f6e89e09 100644
--- a/misc/examples/prime.c
+++ b/misc/examples/prime.c
@@ -2,7 +2,9 @@
#include <math.h>
#include <time.h>
#include <stc/cbits.h>
-#include <stc/views.h>
+#include <stc/algo/filter.h>
+#include <stc/algo/crange.h>
+
cbits sieveOfEratosthenes(size_t n)
{
@@ -41,7 +43,7 @@ int main(void)
puts("");
puts("Show the last 50 primes using a temporary crange generator:");
- c_FORFILTER (i, crange, crange_literal(n - 1, 0, -2)
+ c_FORFILTER (i, crange, crange_LITERAL(n - 1, 0, -2)
, cbits_test(&primes, *i.ref>>1)
, c_FLT_TAKE(i, 50)) {
printf("%lld ", *i.ref);
diff --git a/misc/examples/regex_replace.c b/misc/examples/regex_replace.c
index d621c0db..a170856b 100644
--- a/misc/examples/regex_replace.c
+++ b/misc/examples/regex_replace.c
@@ -26,11 +26,11 @@ int main()
printf("fixed: %s\n", cstr_str(&str));
/* US date format, and add 10 years to dates: */
- cstr_take(&str, cregex_replace_pattern_n(pattern, input, "$1/$3/$2", 0, add_10_years, CREG_DEFAULT));
+ cstr_take(&str, cregex_replace_pattern_ex(pattern, input, "$1/$3/$2", 0, add_10_years, CREG_DEFAULT));
printf("us+10: %s\n", cstr_str(&str));
/* Wrap first date inside []: */
- cstr_take(&str, cregex_replace_pattern_n(pattern, input, "[$0]", 1, NULL, CREG_DEFAULT));
+ cstr_take(&str, cregex_replace_pattern_ex(pattern, input, "[$0]", 1, NULL, CREG_DEFAULT));
printf("brack: %s\n", cstr_str(&str));
/* Shows how to compile RE separately */
diff --git a/misc/examples/utf8replace_c.c b/misc/examples/utf8replace_c.c
index 74b765dc..3645bd0a 100644
--- a/misc/examples/utf8replace_c.c
+++ b/misc/examples/utf8replace_c.c
@@ -8,10 +8,10 @@ int main() {
printf("%s\n", cstr_str(&hello));
/* replace second smiley at utf8 codepoint pos 7 */
- cstr_u8_replace(&hello, cstr_u8_to_pos(&hello, 7), 1, c_SV("🐨"));
+ cstr_u8_replace_at(&hello, cstr_u8_to_pos(&hello, 7), 1, c_SV("🐨"));
printf("%s\n", cstr_str(&hello));
- cstr_replace(&hello, "🐨", "ø", 1);
+ cstr_replace_ex(&hello, "🐨", "ø", 1);
printf("%s\n", cstr_str(&hello));
upper = cstr_toupper_sv(cstr_sv(&hello));