summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/utf8replace_c.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/utf8replace_c.c')
-rw-r--r--misc/examples/utf8replace_c.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/misc/examples/utf8replace_c.c b/misc/examples/utf8replace_c.c
new file mode 100644
index 00000000..22a5c990
--- /dev/null
+++ b/misc/examples/utf8replace_c.c
@@ -0,0 +1,23 @@
+#define i_extern // add utf8 dependencies
+#include <stc/cstr.h>
+#include <stc/csview.h>
+
+int main() {
+ c_auto (cstr, hello, upper) {
+ hello = cstr_lit("hell😀 w😀rld");
+ 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("🐨"));
+ printf("%s\n", cstr_str(&hello));
+
+ cstr_replace(&hello, "🐨", "ø", 1);
+ printf("%s\n", cstr_str(&hello));
+
+ upper = cstr_toupper_sv(cstr_sv(&hello));
+
+ c_foreach (c, cstr, hello)
+ printf("%.*s,", c_ARGSV(c.u8.chr));
+ puts("");
+ }
+}