diff options
Diffstat (limited to 'gdb/common/xml-utils.c')
-rw-r--r-- | gdb/common/xml-utils.c | 49 |
1 files changed, 11 insertions, 38 deletions
diff --git a/gdb/common/xml-utils.c b/gdb/common/xml-utils.c index b5fe442..c6dd2fb 100644 --- a/gdb/common/xml-utils.c +++ b/gdb/common/xml-utils.c @@ -20,64 +20,37 @@ #include "common-defs.h" #include "xml-utils.h" -/* Return a malloc allocated string with special characters from TEXT - replaced by entity references. */ +/* Return a string with special characters from TEXT replaced by entity + references. */ -char * +std::string xml_escape_text (const char *text) { - char *result; - int i, special; - - /* Compute the length of the result. */ - for (i = 0, special = 0; text[i] != '\0'; i++) - switch (text[i]) - { - case '\'': - case '\"': - special += 5; - break; - case '&': - special += 4; - break; - case '<': - case '>': - special += 3; - break; - default: - break; - } + std::string result; /* Expand the result. */ - result = (char *) xmalloc (i + special + 1); - for (i = 0, special = 0; text[i] != '\0'; i++) + for (int i = 0; text[i] != '\0'; i++) switch (text[i]) { case '\'': - strcpy (result + i + special, "'"); - special += 5; + result += "'"; break; case '\"': - strcpy (result + i + special, """); - special += 5; + result += """; break; case '&': - strcpy (result + i + special, "&"); - special += 4; + result += "&"; break; case '<': - strcpy (result + i + special, "<"); - special += 3; + result += "<"; break; case '>': - strcpy (result + i + special, ">"); - special += 3; + result += ">"; break; default: - result[i + special] = text[i]; + result += text[i]; break; } - result[i + special] = '\0'; return result; } |