summaryrefslogtreecommitdiffhomepage
path: root/misc/examples/cstr_match.c
diff options
context:
space:
mode:
Diffstat (limited to 'misc/examples/cstr_match.c')
-rw-r--r--misc/examples/cstr_match.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/misc/examples/cstr_match.c b/misc/examples/cstr_match.c
new file mode 100644
index 00000000..286ba505
--- /dev/null
+++ b/misc/examples/cstr_match.c
@@ -0,0 +1,23 @@
+#include <stc/cstr.h>
+#include <stc/csview.h>
+#include <stdio.h>
+
+int main()
+{
+ c_with (cstr ss = cstr_lit("The quick brown fox jumps over the lazy dog.JPG"), cstr_drop(&ss)) {
+ size_t pos = cstr_find_at(&ss, 0, "brown");
+ printf("%" c_ZU " [%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_ZU ", %" c_ZU "\n", cstr_str(&s1), cstr_u8_size(&s1), cstr_size(&s1));
+ printf("ch1: %.*s\n", c_ARGSV(ch1));
+ printf("ch2: %.*s\n", c_ARGSV(ch2));
+ }
+}