diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-11-27 00:01:52 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2013-11-27 00:01:52 +0200 |
commit | 690ec7913002d28537dbfc04532b17a10ee56ab3 (patch) | |
tree | dc090af5bf705a8a0e7a47d42159048a1979f770 /src | |
parent | 83a06bbc6b3796a0b8646816da34c6672488cbf0 (diff) | |
download | grecs-690ec7913002d28537dbfc04532b17a10ee56ab3.tar.gz grecs-690ec7913002d28537dbfc04532b17a10ee56ab3.tar.bz2 |
New text formatting functions.
* src/txtacc.c (grecs_txtacc_grow_string)
(grecs_txtacc_grow_string_escape): New functions.
* src/grecs.hin: Ditto
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, ...); | |||
409 | struct grecs_txtacc *grecs_txtacc_create(void); | 409 | struct grecs_txtacc *grecs_txtacc_create(void); |
410 | void grecs_txtacc_free(struct grecs_txtacc *acc); | 410 | void grecs_txtacc_free(struct grecs_txtacc *acc); |
411 | void grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size); | 411 | void grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size); |
412 | void grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf); | ||
413 | void grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc, | ||
414 | const char *buf); | ||
412 | #define grecs_txtacc_grow_char(acc,c) \ | 415 | #define grecs_txtacc_grow_char(acc,c) \ |
413 | do { \ | 416 | do { \ |
414 | char __ch = c; \ | 417 | 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 | |||
106 | grecs_txtacc_free(struct grecs_txtacc *acc) | 106 | grecs_txtacc_free(struct grecs_txtacc *acc) |
107 | { | 107 | { |
108 | if (acc) { | 108 | if (acc) { |
109 | grecs_list_free (acc->cur); | 109 | grecs_list_free(acc->cur); |
110 | grecs_list_free (acc->mem); | 110 | grecs_list_free(acc->mem); |
111 | free (acc); | 111 | free(acc); |
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
@@ -126,6 +126,22 @@ grecs_txtacc_grow(struct grecs_txtacc *acc, const char *buf, size_t size) | |||
126 | } | 126 | } |
127 | } | 127 | } |
128 | 128 | ||
129 | void | ||
130 | grecs_txtacc_grow_string(struct grecs_txtacc *acc, const char *buf) | ||
131 | { | ||
132 | grecs_txtacc_grow(acc, buf, strlen(buf)); | ||
133 | } | ||
134 | |||
135 | void | ||
136 | grecs_txtacc_grow_string_escape(struct grecs_txtacc *acc, const char *buf) | ||
137 | { | ||
138 | for (; *buf; buf++) { | ||
139 | if (strchr(" \t\n\"\'\\", *buf)) | ||
140 | grecs_txtacc_grow_char(acc, '\\'); | ||
141 | grecs_txtacc_grow_char(acc, *buf); | ||
142 | } | ||
143 | } | ||
144 | |||
129 | char * | 145 | char * |
130 | grecs_txtacc_finish(struct grecs_txtacc *acc, int steal) | 146 | grecs_txtacc_finish(struct grecs_txtacc *acc, int steal) |
131 | { | 147 | { |