Lucas De Marchi | b4d1f44 | 2014-10-11 13:03:21 -0300 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include <stdbool.h> |
| 4 | |
| 5 | /* |
| 6 | * Buffer abstract data type |
| 7 | */ |
Lucas De Marchi | 15a7ae3 | 2014-10-11 13:25:51 -0300 | [diff] [blame] | 8 | struct strbuf { |
Lucas De Marchi | b4d1f44 | 2014-10-11 13:03:21 -0300 | [diff] [blame] | 9 | char *bytes; |
| 10 | unsigned size; |
| 11 | unsigned used; |
| 12 | }; |
| 13 | |
Lucas De Marchi | 15a7ae3 | 2014-10-11 13:25:51 -0300 | [diff] [blame] | 14 | void strbuf_init(struct strbuf *buf); |
| 15 | void strbuf_release(struct strbuf *buf); |
| 16 | void strbuf_clear(struct strbuf *buf); |
Lucas De Marchi | b4d1f44 | 2014-10-11 13:03:21 -0300 | [diff] [blame] | 17 | |
| 18 | /* Destroy buffer and return a copy as a C string */ |
Lucas De Marchi | 15a7ae3 | 2014-10-11 13:25:51 -0300 | [diff] [blame] | 19 | char *strbuf_steal(struct strbuf *buf); |
Lucas De Marchi | b4d1f44 | 2014-10-11 13:03:21 -0300 | [diff] [blame] | 20 | |
| 21 | /* |
| 22 | * Return a C string owned by the buffer invalidated if the buffer is |
| 23 | * changed). |
| 24 | */ |
Lucas De Marchi | 15a7ae3 | 2014-10-11 13:25:51 -0300 | [diff] [blame] | 25 | const char *strbuf_str(struct strbuf *buf); |
Lucas De Marchi | b4d1f44 | 2014-10-11 13:03:21 -0300 | [diff] [blame] | 26 | |
Lucas De Marchi | 15a7ae3 | 2014-10-11 13:25:51 -0300 | [diff] [blame] | 27 | bool strbuf_pushchar(struct strbuf *buf, char ch); |
| 28 | unsigned strbuf_pushchars(struct strbuf *buf, const char *str); |
| 29 | void strbuf_popchar(struct strbuf *buf); |
| 30 | void strbuf_popchars(struct strbuf *buf, unsigned n); |