Add buffer_add_xmlescaped, and malloc--

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
This commit is contained in:
Pierre Habouzit 2008-06-22 16:02:13 +02:00
parent 0ad600ef0a
commit c3e01fdd43
3 changed files with 36 additions and 5 deletions

View File

@ -104,3 +104,33 @@ char *buffer_detach(buffer_t *buf)
buffer_init(buf);
return res;
}
void buffer_add_xmlescaped(buffer_t *buf, const char *s)
{
for (;;) {
int len = strcspn(s, "&<>'\"");
buffer_add(buf, s, len);
s += len;
switch (*s++) {
case '\0':
return;
case '&':
buffer_adds(buf, "&amp;");
break;
case '<':
buffer_adds(buf, "&lt;");
break;
case '>':
buffer_adds(buf, "&gt;");
break;
case '\'':
/* OG: why not use default? */
buffer_adds(buf, "&#39;");
break;
case '"':
buffer_adds(buf, "&#34;");
break;
}
}
}

View File

@ -109,7 +109,7 @@ buffer_splice(buffer_t *buf, int pos, int len, const void *data, int dlen)
}
static inline void buffer_add(buffer_t *buf, void *data, int len) {
static inline void buffer_add(buffer_t *buf, const void *data, int len) {
buffer_splice(buf, buf->len, 0, data, len);
}
static inline void buffer_adds(buffer_t *buf, const char *s) {
@ -127,4 +127,7 @@ void buffer_addvf(buffer_t *buf, const char *fmt, va_list)
void buffer_addf(buffer_t *buf, const char *fmt, ...)
__attribute__((format(printf, 2, 3)));
void buffer_add_xmlescaped(buffer_t *buf, const char *s);
#endif /* MC_BASE_BUFFER_H */

View File

@ -126,11 +126,9 @@ markup_parse_text(GMarkupParseContext *context __attribute__ ((unused)),
GError **error __attribute__ ((unused)))
{
markup_parser_data_t *p = (markup_parser_data_t *) user_data;
char *esc;
esc = g_markup_escape_text(text, text_len);
buffer_adds(&p->text, esc);
p_delete(&esc);
buffer_grow(&p->text, text_len);
buffer_add_xmlescaped(&p->text, text);
}
/** Create a markup_parser_data_t structure with elements list.