diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/grecs.hin | 3 | ||||
-rw-r--r-- | src/txtacc.c | 22 |
2 files changed, 22 insertions, 3 deletions
diff --git a/src/grecs.hin b/src/grecs.hin index e83b855..1a591d3 100644 --- a/src/grecs.hin +++ b/src/grecs.hin @@ -409,6 +409,9 @@ int grecs_asprintf(char **pbuf, size_t *psize, const char *fmt, ...); struct grecs_txtacc *grecs_txtacc_create(void); void grecs_txtacc_free(struct grecs_txtacc *acc); void grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size); +void grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf); +void grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc, + const char *buf); #define grecs_txtacc_grow_char(acc,c) \ do { \ char __ch = c; \ diff --git a/src/txtacc.c b/src/txtacc.c index a8fa002..f416006 100644 --- a/src/txtacc.c +++ b/src/txtacc.c @@ -106,9 +106,9 @@ void grecs_txtacc_free(struct grecs_txtacc *acc) { if (acc) { - grecs_list_free (acc->cur); - grecs_list_free (acc->mem); - free (acc); + grecs_list_free(acc->cur); + grecs_list_free(acc->mem); + free(acc); } } @@ -126,6 +126,22 @@ grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size) } } +void +grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf) +{ + grecs_txtacc_grow(acc, buf, strlen(buf)); +} + +void +grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc, const char *buf) +{ + for (; *buf; buf++) { + if (strchr(" \t\n\"\'\\", *buf)) + grecs_txtacc_grow_char(acc, '\\'); + grecs_txtacc_grow_char(acc, *buf); + } +} + char * grecs_txtacc_finish(struct grecs_txtacc *acc, int steal) { |