summaryrefslogtreecommitdiffhomepage
path: root/examples/utf8replace_c.c
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/utf8replace_c.c
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/utf8replace_c.c')
-rw-r--r--examples/utf8replace_c.c16
1 files changed, 9 insertions, 7 deletions
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("");
}
}