cstring

A simple and lightweight string library for C
git clone git://git.christosmarg.xyz/cstring.git
Log | Files | Refs | README

test.c (1440B)


      1 #include "cstring.h"
      2 
      3 // Compilation: gcc test.c -lcstring
      4 
      5 int
      6 main(int argc, char **argv)
      7 {
      8     cstring s = cstring_create("Hello world");
      9     printf("cstring_create: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     10 
     11     cstring_append(&s, "Append");
     12     printf("cstring_append: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     13 
     14     cstring_assign(&s, "New string");
     15     printf("cstring_assign: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     16 
     17     cstring_push_back(&s, 'c');
     18     printf("cstring_push_back: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     19 
     20     cstring_insert(&s, "Inserted text", 4);
     21     printf("cstring_insert: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     22     
     23     cstring_pop_back(&s);
     24     printf("cstring_pop_back: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     25 
     26     cstring_clear(&s);
     27     printf("cstring_clear: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     28 
     29     cstring_assign(&s, "CSTRING");
     30     printf("cstring_assign: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     31     printf("cstring_front: %c\n", cstring_front(&s));
     32     printf("cstring_back: %c\n", cstring_back(&s));
     33 
     34     cstring_replace_char(&s, 3, 'x');
     35     printf("cstring_replace: %s (Len: %ld, Capacity: %ld)\n", s.str, s.len, s.capacity);
     36 
     37     cstring_delete(&s);
     38     if (cstring_empty(&s)) printf("cstring_delete: Deleted string.\n");
     39 
     40     return 0;
     41 }