static void rndr_smartypants(struct buf *ob, struct buf *text, void *opaque) { struct xhtml_renderopt *options = opaque; size_t i; if (!text) return; for (i = 0; i < text->size; ++i) { size_t sub; char c = text->data[i]; for (sub = 0; sub < SUBS_COUNT; ++sub) { if (c == smartypants_subs[sub].c0 && smartypants_cmpsub(text, i, smartypants_subs[sub].pattern)) { if (smartypants_subs[sub].entity) bufputs(ob, smartypants_subs[sub].entity); i += smartypants_subs[sub].skip; break; } } if (sub < SUBS_COUNT) continue; switch (c) { case '\"': if (smartypants_quotes(ob, text, i, options->quotes.in_dquote)) { options->quotes.in_dquote = !options->quotes.in_dquote; continue; } break; case '\'': if (smartypants_quotes(ob, text, i, options->quotes.in_squote)) { options->quotes.in_squote = !options->quotes.in_squote; continue; } break; } /* * Copy raw character */ put_scaped_char(ob, c); } }
/* sdhtml_escape • copy the buffer entity-escaping '<', '>', '&' and '"' */ void sdhtml_escape(struct buf *ob, const char *src, size_t size) { size_t i = 0, org; while (i < size) { /* copying directly unescaped characters */ org = i; while (i < size && src[i] != '<' && src[i] != '>' && src[i] != '&' && src[i] != '"') i += 1; if (i > org) bufput(ob, src + org, i - org); /* escaping */ if (i >= size) break; put_scaped_char(ob, src[i]); i++; } }