summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings/utf8replace_c.c
diff options
context:
space:
mode:
authorTyge Løvset <[email protected]>2023-07-24 08:48:41 +0200
committerGitHub <[email protected]>2023-07-24 08:48:41 +0200
commit374b3c27831cd4e09461867ed231669777b96951 (patch)
tree88011006f6d536cdb1ad1eca8073392ca80687cc /misc/examples/strings/utf8replace_c.c
parent177418232a2d8a8b0df1667d3e4bd15dc37db59f (diff)
parent650b053f443f9132dadb6d1ca924c0b36849739f (diff)
downloadSTC-modified-374b3c27831cd4e09461867ed231669777b96951.tar.gz
STC-modified-374b3c27831cd4e09461867ed231669777b96951.zip
Merge pull request #65 from stclib/dev43
Dev43
Diffstat (limited to 'misc/examples/strings/utf8replace_c.c')
-rw-r--r--misc/examples/strings/utf8replace_c.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/misc/examples/strings/utf8replace_c.c b/misc/examples/strings/utf8replace_c.c
new file mode 100644
index 00000000..1d54486f
--- /dev/null
+++ b/misc/examples/strings/utf8replace_c.c
@@ -0,0 +1,25 @@
+#define i_implement
+#include <stc/cstr.h>
+
+int main(void)
+{
+ cstr hello = cstr_lit("hell😀 w😀rld");
+ printf("%s\n", cstr_str(&hello));
+
+ /* replace second smiley at utf8 codepoint pos 7 */
+ cstr_u8_replace_at(&hello,
+ cstr_u8_to_pos(&hello, 7),
+ 1,
+ c_sv("🐨")
+ );
+ printf("%s\n", cstr_str(&hello));
+
+ c_foreach (c, cstr, hello)
+ printf("%.*s,", c_SV(c.u8.chr));
+
+ cstr str = cstr_lit("scooby, dooby doo");
+ cstr_replace(&str, "oo", "00");
+ printf("\n%s\n", cstr_str(&str));
+
+ c_drop(cstr, &hello, &str);
+}