/* This software is licensed by the MIT License, see LICENSE file */ /* Copyright © 2022 Gregory Lirent */ #include "plug.h" static void string_print_compare(const vtype_string* s0, const vtype_string* s1) { int c = string_compare(s0, s1); char* m; if (c == 0) m = "=="; else m = (c < 0) ? "<" : ">"; puts("\e[36mStrings comparsion:\e[m\n"); printf("\e[33m\"%s\"\e[m \e[31m%s\e[m \e[33m\"%s\"\e[m\n", s0->buffer, m, s1->buffer); } static void string_print_case_compare(const vtype_string* s0, const vtype_string* s1) { int c = string_case_compare(s0, s1); char* m; if (c == 0) m = "=="; else m = (c < 0) ? "<" : ">"; puts("\e[36mStrings case insensitive comparsion:\e[m\n"); printf("\e[33m\"%s\"\e[m \e[31m%s\e[m \e[33m\"%s\"\e[m\n", s0->buffer, m, s1->buffer); } int main(int argc, char** argv) { test_init(argc, argv); vtype_string x, y; x = string_random(30); string_print(&x, "(part 1)"); string_concat(&x, '\n'); string_concat_random(&x, 30); { char* repl = random_utf8_cstring(30); void* hack = string_at(&x, 31); string_print((void*)&hack, "(part 2)"); string_print((void*)&repl, "(part 2 replaced)"); string_replace(&x, hack, repl, -1); free(repl); } string_info(&x); string_print(&x, "concatenated"); do { string_replace_random(&x, 12); } while (string_size(&x) == string_nmemb(&x)); y = string_copy(&x); string_to_lower(&x); string_to_upper(&y); string_print_compare(&x, &y); string_print_case_compare(&x, &y); string_reverse(&y); string_capitalize(&y); string_print(&y, "reversed & capitalized"); string_free(&x); string_free(&y); }