blob: 0f7ceb168ab4085c8b529553e0466101b3f0dc4d [file] [log] [blame]
Lucas De Marchib4d1f442014-10-11 13:03:21 -03001#pragma once
2
3#include <stdbool.h>
4
5/*
6 * Buffer abstract data type
7 */
Lucas De Marchi15a7ae32014-10-11 13:25:51 -03008struct strbuf {
Lucas De Marchib4d1f442014-10-11 13:03:21 -03009 char *bytes;
10 unsigned size;
11 unsigned used;
12};
13
Lucas De Marchi15a7ae32014-10-11 13:25:51 -030014void strbuf_init(struct strbuf *buf);
15void strbuf_release(struct strbuf *buf);
16void strbuf_clear(struct strbuf *buf);
Lucas De Marchib4d1f442014-10-11 13:03:21 -030017
18/* Destroy buffer and return a copy as a C string */
Lucas De Marchi15a7ae32014-10-11 13:25:51 -030019char *strbuf_steal(struct strbuf *buf);
Lucas De Marchib4d1f442014-10-11 13:03:21 -030020
21/*
22 * Return a C string owned by the buffer invalidated if the buffer is
23 * changed).
24 */
Lucas De Marchi15a7ae32014-10-11 13:25:51 -030025const char *strbuf_str(struct strbuf *buf);
Lucas De Marchib4d1f442014-10-11 13:03:21 -030026
Lucas De Marchi15a7ae32014-10-11 13:25:51 -030027bool strbuf_pushchar(struct strbuf *buf, char ch);
28unsigned strbuf_pushchars(struct strbuf *buf, const char *str);
29void strbuf_popchar(struct strbuf *buf);
30void strbuf_popchars(struct strbuf *buf, unsigned n);