summaryrefslogtreecommitdiff
path: root/imap-send.c
diff options
context:
space:
mode:
authorMichael Haggerty <mhagger@alum.mit.edu>2012-11-25 11:08:40 (GMT)
committerJunio C Hamano <gitster@pobox.com>2012-11-29 21:43:04 (GMT)
commit3c64063558d57735384d3c547c0138aca7dfd3b8 (patch)
tree5c0aca85ed604ca5f8a3bed7d4c44e79f22844e0 /imap-send.c
parentf035ab620520dbf286d3303194f10a489d7c7f56 (diff)
downloadgit-3c64063558d57735384d3c547c0138aca7dfd3b8.zip
git-3c64063558d57735384d3c547c0138aca7dfd3b8.tar.gz
git-3c64063558d57735384d3c547c0138aca7dfd3b8.tar.bz2
wrap_in_html(): use strbuf_addstr_xml_quoted()
Use the new function to quote characters as they are being added to buf, rather than quoting them in *p and then copying them into buf. This increases code sharing, and changes the algorithm from O(N^2) to O(N) in the number of characters in a line. Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'imap-send.c')
-rw-r--r--imap-send.c23
1 files changed, 4 insertions, 19 deletions
diff --git a/imap-send.c b/imap-send.c
index a5e0e33..b73c913 100644
--- a/imap-send.c
+++ b/imap-send.c
@@ -1339,21 +1339,6 @@ static int imap_store_msg(struct store *gctx, struct msg_data *msg)
return DRV_OK;
}
-static void encode_html_chars(struct strbuf *p)
-{
- int i;
- for (i = 0; i < p->len; i++) {
- if (p->buf[i] == '&')
- strbuf_splice(p, i, 1, "&amp;", 5);
- if (p->buf[i] == '<')
- strbuf_splice(p, i, 1, "&lt;", 4);
- if (p->buf[i] == '>')
- strbuf_splice(p, i, 1, "&gt;", 4);
- if (p->buf[i] == '"')
- strbuf_splice(p, i, 1, "&quot;", 6);
- }
-}
-
static void wrap_in_html(struct strbuf *msg)
{
struct strbuf buf = STRBUF_INIT;
@@ -1372,12 +1357,12 @@ static void wrap_in_html(struct strbuf *msg)
strbuf_addbuf(&buf, *p);
strbuf_addstr(&buf, pre_open);
added_header = 1;
- continue;
+ } else {
+ strbuf_addbuf(&buf, *p);
}
+ } else {
+ strbuf_addstr_xml_quoted(&buf, (*p)->buf);
}
- else
- encode_html_chars(*p);
- strbuf_addbuf(&buf, *p);
}
strbuf_addstr(&buf, pre_close);
strbuf_list_free(lines);