summaryrefslogtreecommitdiffabout
path: root/src
authorSergey Poznyakoff <gray@gnu.org.ua>2013-11-26 22:01:52 (GMT)
committer Sergey Poznyakoff <gray@gnu.org.ua>2013-11-26 22:01:52 (GMT)
commit690ec7913002d28537dbfc04532b17a10ee56ab3 (patch) (side-by-side diff)
treedc090af5bf705a8a0e7a47d42159048a1979f770 /src
parent83a06bbc6b3796a0b8646816da34c6672488cbf0 (diff)
downloadgrecs-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') (more/less context) (ignore whitespace changes)
-rw-r--r--src/grecs.hin3
-rw-r--r--src/txtacc.c22
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)
{

Return to:

Send suggestions and report system problems to the System administrator.