-/* $Id: html.c,v 1.76 2009/11/01 07:44:32 kristaps Exp $ */
+/* $Id: html.c,v 1.78 2009/11/01 15:34:15 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
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("<");
+ } else if ('\0' == *p)
break;
- case ('>'):
+
+ if ('<' == *p)
+ printf("<");
+ else if ('>' == *p)
printf(">");
- break;
- case ('&'):
+ else if ('&' == *p)
printf("&");
- break;
- default:
- putchar(*p);
- break;
- }
}
}
if ( ! (HTML_NOSPACE & h->flags))
if ( ! (HTML_CLRLINE & htmltags[tag].flags))
- printf(" ");
+ putchar(' ');
printf("<%s", htmltags[tag].name);
for (i = 0; i < sz; i++) {
printf(" %s=\"", htmlattrs[p[i].key]);
assert(p->val);
print_encode(h, p[i].val);
- printf("\"");
+ putchar('\"');
}
- printf(">");
+ putchar('>');
h->flags |= HTML_NOSPACE;
if (HTML_CLRLINE & htmltags[tag].flags)
if (HTML_CLRLINE & htmltags[tag].flags) {
h->flags |= HTML_NOSPACE;
h->flags |= HTML_NEWLINE;
- printf("\n");
+ putchar('\n');
} else
h->flags &= ~HTML_NEWLINE;
}
}
if ( ! (h->flags & HTML_NOSPACE))
- printf(" ");
+ putchar(' ');
h->flags &= ~HTML_NOSPACE;
h->flags &= ~HTML_NEWLINE;