aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2017-12-24 09:08:58 +0100
committerGravatar Hanspeter Portner <dev@open-music-kontrollers.ch>2017-12-24 09:14:30 +0100
commit4e2bf167096e630bcb0415499123524122e65d81 (patch)
tree29e8a95bce009dc1f9be580bfa0320f1ba9100bc
parentedbd2dcae95798ea77a2e0900404f268a33a73e3 (diff)
downloadlv2lint-4e2bf167096e630bcb0415499123524122e65d81.zip
lv2lint-4e2bf167096e630bcb0415499123524122e65d81.tar.gz
lv2lint-4e2bf167096e630bcb0415499123524122e65d81.tar.bz2
lv2lint-4e2bf167096e630bcb0415499123524122e65d81.tar.xz
Make html escaping more efficient.
-rw-r--r--VERSION2
-rw-r--r--lv2lint.c60
2 files changed, 41 insertions, 21 deletions
diff --git a/VERSION b/VERSION
index d28e773..4fca9d0 100644
--- a/VERSION
+++ b/VERSION
@@ -1 +1 @@
-0.1.211
+0.1.213
diff --git a/lv2lint.c b/lv2lint.c
index 40c1f89..991a6d2 100644
--- a/lv2lint.c
+++ b/lv2lint.c
@@ -1227,49 +1227,69 @@ lv2lint_printf(app_t *app, const char *fmt, ...)
static void
_escape_markup(char *docu)
{
- char *ptr = docu;
- char *tag = NULL;
- char *amp = NULL;
+ char *wrp = docu;
+ bool tag = false;
+ bool amp = false;
+ bool sep = false;
- while(*ptr != '\0')
+ for(const char *rdp = docu; *rdp != '\0'; rdp++)
{
- switch(*ptr)
+ switch(*rdp)
{
case '<':
{
- tag = ptr;
- } break;
+ tag = true;
+ } continue;
case '>':
{
if(tag)
{
- ptr += 1;
- const size_t len = strlen(ptr) + 1;
- memmove(tag, ptr, len);
- ptr = tag - 1;
- tag = NULL;
+ tag = false;
+ continue;
}
} break;
case '&':
{
- amp = ptr;
- } break;
+ amp = true;
+ } continue;
case ';':
{
if(amp)
{
- ptr += 1;
- const size_t len = strlen(ptr) + 1;
- memmove(amp, ptr, len);
- ptr = amp - 1;
- amp = NULL;
+ amp = false;
+ continue;
}
} break;
+
+ case ' ':
+ {
+ if(sep) // escape double spaces
+ {
+ continue;
+ }
+
+ sep = true;
+ } break;
+
+ default:
+ {
+ sep = false;
+ } break;
}
- ptr += 1;
+ if(tag || amp)
+ {
+ continue;
+ }
+
+ if(wrp != rdp)
+ {
+ *wrp++ = *rdp;
+ }
}
+
+ *wrp = '\0';
}
static void