Archived
1
0
Fork 0

core string buffer implementation.

This commit is contained in:
H Hautakoski 2010-07-12 00:01:35 +02:00 committed by Henrik Hautakoski
parent f35b780e53
commit 92477a7261
4 changed files with 207 additions and 0 deletions

49
test/t_strbuf.c Normal file
View file

@ -0,0 +1,49 @@
#include <stdio.h>
#include <malloc.h>
#include "../src/common/strbuf.h"
void print_strbuf(strbuf_t *s) {
printf("block: %i, len: %i |%s|\n", s->alloc_size, s->len, s->buf);
}
int main() {
strbuf_t b = STRBUF_INIT;
char *str;
strbuf_append(&b, " ", 4);
strbuf_append(&b, "abcdef", 6);
print_strbuf(&b);
strbuf_append(&b, "012345678901234567890123456789", 30);
strbuf_append(&b, " ", 6);
print_strbuf(&b);
strbuf_rtrim(&b);
print_strbuf(&b);
strbuf_ltrim(&b);
print_strbuf(&b);
strbuf_trim(&b);
print_strbuf(&b);
strbuf_rev(&b);
print_strbuf(&b);
str = strbuf_release(&b);
printf("released |%s|\n", str);
free(str);
return 0;
}