1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-15 01:57:40 -05:00

Add a 'strbuf' system, for building up a large string piece by piece.

I'm faintly surprised I haven't needed this before. Basically it's an
allocating string formatter, like dupprintf, except that it
concatenates on to the end of a previous string. You instantiate a
strbuf, then repeatedly call strbuf_catf to append pieces of formatted
output to it, and then you can extract the whole string and free it
(separately or both in one step).
This commit is contained in:
Simon Tatham
2017-01-21 14:55:53 +00:00
parent 23a9d5608c
commit 960ad594a3
2 changed files with 72 additions and 16 deletions

7
misc.h
View File

@ -38,6 +38,13 @@ char *dupprintf(const char *fmt, ...)
;
char *dupvprintf(const char *fmt, va_list ap);
void burnstr(char *string);
typedef struct strbuf strbuf;
strbuf *strbuf_new(void);
void strbuf_free(strbuf *buf);
char *strbuf_str(strbuf *buf); /* does not free buf */
char *strbuf_to_str(strbuf *buf); /* does free buf, but you must free result */
void strbuf_catf(strbuf *buf, const char *fmt, ...);
void strbuf_catfv(strbuf *buf, const char *fmt, va_list ap);
/* String-to-Unicode converters that auto-allocate the destination and
* work around the rather deficient interface of mb_to_wc.