summaryrefslogtreecommitdiff
path: root/xml.c
diff options
context:
space:
mode:
authorHiltjo Posthuma <hiltjo@codemadness.org>2015-08-08 00:06:06 +0200
committerHiltjo Posthuma <hiltjo@codemadness.org>2015-08-08 00:06:06 +0200
commitaee6c97096e319b8a4d5a4744002bd0f18398fb2 (patch)
treef8682f56c74ee52196c6d67a70900359c0884744 /xml.c
parentf7c579c3b8e77215d60f1948367221b738823585 (diff)
xml: move entity to namedentitystr()
Diffstat (limited to 'xml.c')
-rw-r--r--xml.c35
1 files changed, 16 insertions, 19 deletions
diff --git a/xml.c b/xml.c
index 079b106..ad191de 100644
--- a/xml.c
+++ b/xml.c
@@ -8,23 +8,6 @@
#include "xml.h"
-static const struct {
- char *entity;
- size_t len;
- int c;
-} entities[] = {
- { .entity = "&lt;", .len = 4, .c = '<' },
- { .entity = "&gt;", .len = 4, .c = '>' },
- { .entity = "&apos;", .len = 6, .c = '\'' },
- { .entity = "&amp;", .len = 5, .c = '&' },
- { .entity = "&quot;", .len = 6, .c = '"' },
- { .entity = "&LT;", .len = 4, .c = '<' },
- { .entity = "&GT;", .len = 4, .c = '>' },
- { .entity = "&APOS;", .len = 6, .c = '\'' },
- { .entity = "&AMP;", .len = 5, .c = '&' },
- { .entity = "&QUOT;", .len = 6, .c = '"' }
-};
-
static int
xmlparser_string_getnext(XMLParser *x)
{
@@ -279,6 +262,21 @@ xml_codepointtoutf8(uint32_t cp, uint32_t *utf)
ssize_t
xml_namedentitytostr(const char *e, char *buf, size_t bufsiz)
{
+ const struct {
+ char *entity;
+ int c;
+ } entities[] = {
+ { .entity = "&amp;", .c = '&' },
+ { .entity = "&lt;", .c = '<' },
+ { .entity = "&gt;", .c = '>' },
+ { .entity = "&apos;", .c = '\'' },
+ { .entity = "&quot;", .c = '"' },
+ { .entity = "&AMP;", .c = '&' },
+ { .entity = "&LT;", .c = '<' },
+ { .entity = "&GT;", .c = '>' },
+ { .entity = "&APOS;", .c = '\'' },
+ { .entity = "&QUOT;", .c = '"' }
+ };
size_t i;
/* buffer is too small */
@@ -290,8 +288,7 @@ xml_namedentitytostr(const char *e, char *buf, size_t bufsiz)
return 0;
for (i = 0; i < sizeof(entities) / sizeof(*entities); i++) {
- /* NOTE: compares max 6 chars */
- if (!strncmp(e, entities[i].entity, 6)) {
+ if (!strcmp(e, entities[i].entity)) {
buf[0] = entities[i].c;
buf[1] = '\0';
return 1;