diff options
| author | Tyge Løvset <[email protected]> | 2022-12-29 00:28:50 +0100 |
|---|---|---|
| committer | Tyge Løvset <[email protected]> | 2022-12-29 00:28:50 +0100 |
| commit | 0761c13f316cc98ae7756f3527931aa86bed5016 (patch) | |
| tree | e90777558956fcf91d6b1c958e0c3a6fb0ab007f /misc | |
| parent | d623c6c85071b9af5d607bb5d9aceceaea05220a (diff) | |
| download | STC-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')
| -rw-r--r-- | misc/examples/cpque.c | 2 | ||||
| -rw-r--r-- | misc/examples/demos.c | 2 | ||||
| -rw-r--r-- | misc/examples/forfilter.c | 8 | ||||
| -rw-r--r-- | misc/examples/forloops.c | 2 | ||||
| -rw-r--r-- | misc/examples/prime.c | 6 | ||||
| -rw-r--r-- | misc/examples/regex_replace.c | 4 | ||||
| -rw-r--r-- | misc/examples/utf8replace_c.c | 4 | ||||
| -rw-r--r-- | misc/include/alt/cstr.h | 11 |
8 files changed, 21 insertions, 18 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)); diff --git a/misc/include/alt/cstr.h b/misc/include/alt/cstr.h index ecb9c9fb..8de6c4b0 100644 --- a/misc/include/alt/cstr.h +++ b/misc/include/alt/cstr.h @@ -182,12 +182,12 @@ STC_INLINE uint64_t cstr_hash(const cstr *self) { return cfasthash(self->str, _cstr_p(self)->size); } -STC_INLINE void -cstr_replace(cstr* self, const char* find, const char* repl, unsigned count) { - csview in = cstr_sv(self); - cstr_take(self, cstr_replace_sv(in, c_SV(find, strlen(find)), - c_SV(repl, strlen(repl)), count)); +STC_INLINE void cstr_replace_ex(cstr* self, const char* find, const char* repl, unsigned count) { + cstr_take(self, cstr_replace_sv(cstr_sv(self), c_SV(find, strlen(find)), + c_SV(repl, strlen(repl)), count)); } +STC_INLINE void cstr_replace(cstr* self, const char* search, const char* repl) + { cstr_replace_ex(self, search, repl, ~0U); } /* -------------------------- IMPLEMENTATION ------------------------- */ #if defined(i_implement) @@ -324,7 +324,6 @@ STC_DEF cstr cstr_replace_sv(csview str, csview find, csview repl, unsigned count) { cstr out = cstr_NULL; size_t from = 0; char* res; - if (count == 0) count = ~0; if (find.size) while (count-- && (res = cstrnstrn(str.str + from, find.str, str.size - from, find.size))) { const size_t pos = res - str.str; |
