diff options
Diffstat (limited to 'strbuf.h')
-rw-r--r-- | strbuf.h | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -38,6 +38,7 @@ extern void strbuf_resize(strbuf_t *s, int len); | |||
38 | static int strbuf_empty_length(strbuf_t *s); | 38 | static int strbuf_empty_length(strbuf_t *s); |
39 | static int strbuf_length(strbuf_t *s); | 39 | static int strbuf_length(strbuf_t *s); |
40 | static char *strbuf_string(strbuf_t *s, int *len); | 40 | static char *strbuf_string(strbuf_t *s, int *len); |
41 | static void strbuf_ensure_empty_length(strbuf_t *s, int len); | ||
41 | 42 | ||
42 | /* Update */ | 43 | /* Update */ |
43 | extern void strbuf_append_fmt(strbuf_t *s, const char *format, ...); | 44 | extern void strbuf_append_fmt(strbuf_t *s, const char *format, ...); |
@@ -53,6 +54,12 @@ static inline int strbuf_empty_length(strbuf_t *s) | |||
53 | return s->size - s->length - 1; | 54 | return s->size - s->length - 1; |
54 | } | 55 | } |
55 | 56 | ||
57 | static inline void strbuf_ensure_empty_length(strbuf_t *s, int len) | ||
58 | { | ||
59 | if (len > strbuf_empty_length(s)) | ||
60 | strbuf_resize(s, s->length + len); | ||
61 | } | ||
62 | |||
56 | static inline int strbuf_length(strbuf_t *s) | 63 | static inline int strbuf_length(strbuf_t *s) |
57 | { | 64 | { |
58 | return s->length; | 65 | return s->length; |
@@ -60,9 +67,12 @@ static inline int strbuf_length(strbuf_t *s) | |||
60 | 67 | ||
61 | static inline void strbuf_append_char(strbuf_t *s, const char c) | 68 | static inline void strbuf_append_char(strbuf_t *s, const char c) |
62 | { | 69 | { |
63 | if (strbuf_empty_length(s) < 1) | 70 | strbuf_ensure_empty_length(s, 1); |
64 | strbuf_resize(s, s->length + 1); | 71 | s->buf[s->length++] = c; |
72 | } | ||
65 | 73 | ||
74 | static inline void strbuf_append_char_unsafe(strbuf_t *s, const char c) | ||
75 | { | ||
66 | s->buf[s->length++] = c; | 76 | s->buf[s->length++] = c; |
67 | } | 77 | } |
68 | 78 | ||