X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;ds=sidebyside;f=strbuf.c;h=9a373bef70b7fdd434c02d1ca753fcc8f799ecc2;hb=7746f2e319a636cb5be8c1d6ac603585e613562b;hp=05d0693eba1eba4e2f21057388368c0890e668fe;hpb=f6f3921db69a42f0a73d03efd48a2e776dd7ff92;p=git.git diff --git a/strbuf.c b/strbuf.c index 05d0693eb..9a373bef7 100644 --- a/strbuf.c +++ b/strbuf.c @@ -425,6 +425,32 @@ void strbuf_add_lines(struct strbuf *out, const char *prefix, strbuf_complete_line(out); } +void strbuf_addstr_xml_quoted(struct strbuf *buf, const char *s) +{ + while (*s) { + size_t len = strcspn(s, "\"<>&"); + strbuf_add(buf, s, len); + s += len; + switch (*s) { + case '"': + strbuf_addstr(buf, """); + break; + case '<': + strbuf_addstr(buf, "<"); + break; + case '>': + strbuf_addstr(buf, ">"); + break; + case '&': + strbuf_addstr(buf, "&"); + break; + case 0: + return; + } + s++; + } +} + static int is_rfc3986_reserved(char ch) { switch (ch) {