Implement strbuffer

String buffer (strbuffer) is an object that resizes automatically when
data is added to it. It was implemented by generalizing the technique
used in json_dumps().
This commit is contained in:
Petri Lehtinen
2009-06-11 08:56:11 +03:00
parent 9b825f7b18
commit 197d3aa160
4 changed files with 93 additions and 28 deletions

19
src/strbuffer.h Normal file
View File

@@ -0,0 +1,19 @@
#ifndef STRBUFFER_H
#define STRBUFFER_H
typedef struct {
char *value;
int length;
int size;
} strbuffer_t;
void strbuffer_init(strbuffer_t *strbuff);
void strbuffer_close(strbuffer_t *strbuff);
char *strbuffer_value(strbuffer_t *strbuff);
char *strbuffer_steal_value(strbuffer_t *strbuff);
int strbuffer_append(strbuffer_t *strbuff, const char *string);
int strbuffer_append_bytes(strbuffer_t *strbuff, const char *data, int size);
#endif