1 /* Blerg is (C) 2011 The Dominion of Awesome, and is distributed under a
2 * BSD-style license. Please see the COPYING file for details.
8 char *xml_escape(const char *str) {
9 return xml_escape_data(str, strlen(str));
12 char *xml_escape_data(const char *str, int len) {
13 char *r = malloc(len * 5 + 1); /* Up to 5x the space if they're all &'s */
16 for (i = 0, j = 0; i < len; i++) {
19 memcpy(r + j, "<", 4);
23 memcpy(r + j, ">", 4);
27 memcpy(r + j, "&", 5);