summaryrefslogtreecommitdiffhomepage
path: root/examples/utf8replace_c.c
blob: 733245e578a5c77d1800c42a7e83ccceaf1dac2c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#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));

        cstr_replace_sv(
            &hello,
            csview_substr_u8(cstr_sv(&hello), 7, 1),
            c_sv("🐨")
        );
        printf("%s\n", cstr_str(&hello));

        cstr_replace_one(&hello, 0, "🐨", "ø");
        printf("%s\n", cstr_str(&hello));

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