summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2009-11-01 08:15:20 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2009-11-01 08:15:20 +0000
commitc6b6db7485540e4bc78d646fcf1aa938538dea0c (patch)
tree12be2cc2b6f5c42cbd119dba1a5ee2473fb06b57
parentf3bb876e3422b8b2f16b0a2ef93cfde924fe19ee (diff)
downloadmandoc-c6b6db7485540e4bc78d646fcf1aa938538dea0c.tar.gz
mandoc-c6b6db7485540e4bc78d646fcf1aa938538dea0c.tar.zst
mandoc-c6b6db7485540e4bc78d646fcf1aa938538dea0c.zip
print_encode() using strcspn instead of looping/putchar() (noted by Joerg Sonnenberger).
-rw-r--r--html.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/html.c b/html.c
index 7ed94c9a..33c37bb7 100644
--- a/html.c
+++ b/html.c
@@ -1,4 +1,4 @@
-/* $Id: html.c,v 1.76 2009/11/01 07:44:32 kristaps Exp $ */
+/* $Id: html.c,v 1.77 2009/11/01 08:15:20 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
@@ -316,26 +316,26 @@ print_escape(struct html *h, const char **p)
static void
print_encode(struct html *h, const char *p)
{
+ size_t sz;
for (; *p; p++) {
+ sz = strcspn(p, "\\<>&");
+
+ fwrite(p, 1, sz, stdout);
+ p += sz;
+
if ('\\' == *p) {
print_escape(h, &p);
continue;
- }
- switch (*p) {
- case ('<'):
- printf("&lt;");
+ } else if ('\0' == *p)
break;
- case ('>'):
+
+ if ('<' == *p)
+ printf("&lt;");
+ else if ('>' == *p)
printf("&gt;");
- break;
- case ('&'):
+ else if ('&' == *p)
printf("&amp;");
- break;
- default:
- putchar(*p);
- break;
- }
}
}