Mercurial > pidgin.yaz
changeset 18072:3fc94e7c7056
add xmlnode_get_data_unescaped(), and got rid of an unecessary realloc
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 07 Jun 2007 21:14:54 +0000 |
parents | 0b3d6ea61760 |
children | 8bad8a91d128 |
files | libpurple/xmlnode.c libpurple/xmlnode.h |
diffstat | 2 files changed, 28 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/libpurple/xmlnode.c Thu Jun 07 14:48:33 2007 +0000 +++ b/libpurple/xmlnode.c Thu Jun 07 21:14:54 2007 +0000 @@ -333,8 +333,9 @@ for(c = node->child; c; c = c->next) { if(c->type == XMLNODE_TYPE_DATA) { if(!str) - str = g_string_new(""); - str = g_string_append_len(str, c->data, c->data_sz); + str = g_string_new_len(c->data, c->data_sz); + else + str = g_string_append_len(str, c->data, c->data_sz); } } @@ -344,6 +345,18 @@ return g_string_free(str, FALSE); } +char * +xmlnode_get_data_unescaped(xmlnode *node) +{ + char *escaped = xmlnode_get_data(node); + + char *unescaped = escaped ? purple_unescape_html(escaped) : NULL; + + g_free(escaped); + + return unescaped; +} + static char * xmlnode_to_str_helper(xmlnode *node, int *len, gboolean formatting, int depth) {
--- a/libpurple/xmlnode.h Thu Jun 07 14:48:33 2007 +0000 +++ b/libpurple/xmlnode.h Thu Jun 07 21:14:54 2007 +0000 @@ -124,14 +124,24 @@ void xmlnode_insert_data(xmlnode *node, const char *data, gssize size); /** - * Gets data from a node. + * Gets (escaped) data from a node. * * @param node The node to get data from. * - * @return The data from the node. You must g_free + * @return The data from the node. This data is in raw escaped format. + * You must g_free this string when finished using it. + */ +char *xmlnode_get_data(xmlnode *node); + +/** + * Gets unescaped data from a node. + * + * @param node The node to get data from. + * + * @return The data from the node, in unescaped form. You must g_free * this string when finished using it. */ -char *xmlnode_get_data(xmlnode *node); +char *xmlnode_get_data_unescaped(xmlnode *node); /** * Sets an attribute for a node.