X-Git-Url: http://git.tremily.us/?a=blobdiff_plain;f=strbuf.c;h=9a373bef70b7fdd434c02d1ca753fcc8f799ecc2;hb=d4c655271932cd8999a2d8634bde24602c591fe7;hp=05d0693eba1eba4e2f21057388368c0890e668fe;hpb=3a0ee3eb2e83be8a32604850cdf5d6a3439d63b7;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) {