-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.c
More file actions
36 lines (26 loc) · 1.06 KB
/
example.c
File metadata and controls
36 lines (26 loc) · 1.06 KB
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
27
28
29
30
31
32
33
34
35
36
#include <stdio.h>
#include "cstring.h"
void printString(const String *str){
if(str!=NULL)
printf("{%s} // Size: %lu, Capacity: %lu\n", *str, string_size(str), string_capacity(str));
}
int main(){
String *s1 = string_new_copy_cfg("Hello World!", CSTRING_TP_ARR, CSTR_CAPMAN_LOG, 0);
size_t i;
printf("==========Auto-Shrink off==========\n");
printString(s1);
string_erase_n(s1, 5, 6); printString(s1);
string_append_n(s1, " Testing Str", 8);
string_append_one(s1, '.'); printString(s1);
string_erase_n(s1, 0, 7); printString(s1);
printf("\n\n==========Auto-Shrink on / Equal Size==========\n");
string_set_auto_shrink(s1, 1); string_set_cap_man(s1, CSTR_CAPMAN_EQ_SZ); printString(s1);
string_append_all(s1, *s1, CSTRING_TP_STRING);
string_insert_all(s1, i = string_size(s1)/2," -=- ", CSTRING_TP_ARR);
printString(s1);
string_erase(s1, string_size(s1)-1); string_erase_n(s1, i+1, 4); printString(s1);
string_append_all(s1, " String!", CSTRING_TP_ARR); printString(s1);
string_clear(s1); printString(s1);
string_free(s1);
return 0;
}