summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/strings/cstr_match.c
blob: 80013019ea4ad85465c6d7a93187d004c8b467c7 (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
26
#define i_implement
#include <stc/cstr.h>
#include <stc/csview.h>
#include <stdio.h>

int main(void)
{
    cstr ss = cstr_from("The quick brown fox jumps over the lazy dog.JPG");

    intptr_t pos = cstr_find_at(&ss, 0, "brown");
    printf("%" c_ZI " [%s]\n", pos, pos == c_NPOS ? "<NULL>" : cstr_str(&ss) + pos);
    printf("equals: %d\n", cstr_equals(&ss, "The quick brown fox jumps over the lazy dog.JPG"));
    printf("contains: %d\n", cstr_contains(&ss, "umps ove"));
    printf("starts_with: %d\n", cstr_starts_with(&ss, "The quick brown"));
    printf("ends_with: %d\n", cstr_ends_with(&ss, ".jpg"));
    printf("ends_with: %d\n", cstr_ends_with(&ss, ".JPG"));

    cstr s1 = cstr_lit("hell😀 w😀rl🐨");
    csview ch1 = cstr_u8_chr(&s1, 7);
    csview ch2 = cstr_u8_chr(&s1, 10);
    printf("%s\nsize: %" c_ZI ", %" c_ZI "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1));
    printf("ch1: %.*s\n", c_SV(ch1));
    printf("ch2: %.*s\n", c_SV(ch2));

    c_drop(cstr, &ss, &s1);
}