summaryrefslogtreecommitdiffhomepage
path: root/examples/utf8replace_c.c
blob: b43aab6fe1ae5974679dbdfcb28b325379f5ce14 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#define i_implement
#include <stc/cstr.h>
#include <stc/csview.h>

int main() {
    c_auto (cstr, hello) {
        hello = cstr_new("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));

        c_foreach (c, cstr, hello)
            printf("%.*s,", c_ARGsv(c.u8.chr));
        puts("");
    }
}