2014-10-11 23:03:21 +07:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Buffer abstract data type
|
|
|
|
*/
|
2014-10-11 23:25:51 +07:00
|
|
|
struct strbuf {
|
2014-10-11 23:03:21 +07:00
|
|
|
char *bytes;
|
|
|
|
unsigned size;
|
|
|
|
unsigned used;
|
|
|
|
};
|
|
|
|
|
2014-10-11 23:25:51 +07:00
|
|
|
void strbuf_init(struct strbuf *buf);
|
|
|
|
void strbuf_release(struct strbuf *buf);
|
|
|
|
void strbuf_clear(struct strbuf *buf);
|
2014-10-11 23:03:21 +07:00
|
|
|
|
|
|
|
/* Destroy buffer and return a copy as a C string */
|
2014-10-11 23:25:51 +07:00
|
|
|
char *strbuf_steal(struct strbuf *buf);
|
2014-10-11 23:03:21 +07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Return a C string owned by the buffer invalidated if the buffer is
|
|
|
|
* changed).
|
|
|
|
*/
|
2014-10-11 23:25:51 +07:00
|
|
|
const char *strbuf_str(struct strbuf *buf);
|
2014-10-11 23:03:21 +07:00
|
|
|
|
2014-10-11 23:25:51 +07:00
|
|
|
bool strbuf_pushchar(struct strbuf *buf, char ch);
|
|
|
|
unsigned strbuf_pushchars(struct strbuf *buf, const char *str);
|
|
|
|
void strbuf_popchar(struct strbuf *buf);
|
|
|
|
void strbuf_popchars(struct strbuf *buf, unsigned n);
|