summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/utf8replace_c.c
blob: b697efd8376a3ffb4f70d8df62ad8d9955c90dc0 (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
25
#include <stc/cstr.h>

int main()
{
    c_auto (cstr, hello, str)
    {
        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));
        
        str = cstr_lit("scooby, dooby doo");
        cstr_replace(&str, "oo", "00");
        printf("\n%s\n", cstr_str(&str));
    }
}