summaryrefslogtreecommitdiffhomepage
path: root/examples
diff options
context:
space:
mode:
authorTyge Lovset <[email protected]>2022-05-29 00:36:08 +0200
committerTyge Lovset <[email protected]>2022-05-29 00:42:06 +0200
commita341dbc0ce456198d5773c7260e93e8433228ee2 (patch)
tree7759f0cf00201b348bb90868e4553aaed0e3c98e /examples
parent06c8dffeb571a3aa6143425704062de4aa879d2c (diff)
downloadSTC-modified-a341dbc0ce456198d5773c7260e93e8433228ee2.tar.gz
STC-modified-a341dbc0ce456198d5773c7260e93e8433228ee2.zip
Renamed cstr_replace_first() => cstr_replace_one().
cstr.h now #include "utf8.h". Added iterator (utf8) to cstr and other utf8 functions postfixed by _u8(). Also renamed some utf8 functions in csview to better names.
Diffstat (limited to 'examples')
-rw-r--r--examples/cstr_match.c7
-rw-r--r--examples/demos.c2
-rw-r--r--examples/replace.c1
-rw-r--r--examples/utf8replace_c.c16
4 files changed, 17 insertions, 9 deletions
diff --git a/examples/cstr_match.c b/examples/cstr_match.c
index cd3f04be..637fa7f9 100644
--- a/examples/cstr_match.c
+++ b/examples/cstr_match.c
@@ -1,4 +1,5 @@
#include <stc/cstr.h>
+#include <stc/csview.h>
#include <stdio.h>
int main()
@@ -11,5 +12,11 @@ int main()
printf("starts_with: %d\n", cstr_starts_with(ss, "The quick brown"));
printf("ends_with: %d\n", cstr_ends_with(ss, ".jpg"));
printf("ends_with: %d\n", cstr_ends_with(ss, ".JPG"));
+
+ cstr s1 = cstr_new("hell😀 w😀rl🐨");
+ csview ch1 = cstr_at(&s1, 10);
+ csview ch2 = cstr_at_u8(&s1, 10);
+ printf("ch1: %" c_PRIsv "\n", c_ARGsv(ch1));
+ printf("ch2: %" c_PRIsv "\n", c_ARGsv(ch2));
}
}
diff --git a/examples/demos.c b/examples/demos.c
index 99b9e570..c0cecac2 100644
--- a/examples/demos.c
+++ b/examples/demos.c
@@ -13,7 +13,7 @@ void stringdemo1()
cstr_erase_n(&cs, 7, 5); // -nine
printf("%s.\n", cstr_str(&cs));
- cstr_replace_first(&cs, 0, "seven", "four");
+ cstr_replace_one(&cs, 0, "seven", "four");
printf("%s.\n", cstr_str(&cs));
cstr_take(&cs, cstr_from_fmt("%s *** %s", cstr_str(&cs), cstr_str(&cs)));
diff --git a/examples/replace.c b/examples/replace.c
index a5bcf4d3..f658fb3c 100644
--- a/examples/replace.c
+++ b/examples/replace.c
@@ -1,6 +1,5 @@
#include <stc/cstr.h>
-#include <stc/utf8.h>
int main ()
{
diff --git a/examples/utf8replace_c.c b/examples/utf8replace_c.c
index 6b3fcebe..89d5375f 100644
--- a/examples/utf8replace_c.c
+++ b/examples/utf8replace_c.c
@@ -1,21 +1,23 @@
#include <stc/cstr.h>
#include <stc/csview.h>
-#include <stc/utf8.h>
int main() {
c_auto (cstr, hello) {
- hello = cstr_new("hell😀 world");
+ hello = cstr_new("hell😀 w😀rld");
printf("%s\n", cstr_str(&hello));
cstr_replace_sv(
- &hello,
- utf8_substr(cstr_str(&hello), 4, 1),
+ &hello,
+ csview_substr_u8(cstr_sv(&hello), 7, 1),
c_sv("🐨")
);
printf("%s\n", cstr_str(&hello));
- csview sv = csview_from_s(&hello);
- c_foreach (c, csview, sv)
- printf("%" c_PRIsv ",", c_ARGsv(c.codep));
+ cstr_replace_one(&hello, 0, "🐨", "ø");
+ printf("%s\n", cstr_str(&hello));
+
+ c_foreach (c, cstr, hello)
+ printf("%" c_PRIsv ",", c_ARGsv(c.chr));
+ puts("");
}
}