summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings
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/examples/strings
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/examples/strings')
-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
6 files changed, 29 insertions, 29 deletions
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");