libcdsb/examples/string.c

43 lines
1.1 KiB
C
Raw Normal View History

2022-08-16 21:11:07 +03:00
/* This software is licensed by the MIT License, see LICENSE file */
/* Copyright © 2022 Gregory Lirent */
#include <stdio.h>
#include "../include/extra/string.h"
#include "../include/extra/array.h"
typedef vtype_string str_t;
typedef vtype_array arr_t;
int main(int argc, char** argv) {
str_t str;
string_init(&str, "sed ut perspiciatis");
string_concat(&str, ", Unde omnis iste natus error sit voluptatem accusantium doloremque laudantium");
string_concat(&str, ", Totam rem aperiam eaque ipsa");
string_concat(&str, ", Quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt");
string_concat(&str, ", Explicabo.");
string_capitalize(&str);
string_reverse(&str);
printf("%s\n", str.buffer);
arr_t parts = string_split(&str, ',', -1);
printf("%lu\n", array_size(&parts));
for (size_t i = 0; i < array_size(&parts); ++i) {
str_t* value = array_at(&parts, i);
string_trim_spaces(value);
printf("%s (%lu)\n", value->buffer, string_nmemb(value));
}
array_free(&parts);
string_free(&str);
}