Commit 7762bb15 authored by William M. Brack's avatar William M. Brack
Browse files

added a routine xmlStrncatNew to create a new string from 2 frags. added

* parser.c, include/libxml/parser.h: added a routine
  xmlStrncatNew to create a new string from 2 frags.
* tree.c: added code to check if node content is from
  dictionary before trying to change or concatenate.
parent 24d90485
Sun Jan 4 22:45:14 HKT 2004 William Brack <wbarck@mmm.com.hk>
* parser.c, include/libxml/parser.h: added a routine
xmlStrncatNew to create a new string from 2 frags.
* tree.c: added code to check if node content is from
dictionary before trying to change or concatenate.
Sun Jan 4 08:57:51 HKT 2004 William Brack <wbrack@mmm.com.hk>
 
* xmlmemory.c: applied suggestion from Miloslav Trmac (see
......
......@@ -861,6 +861,11 @@ XMLPUBFUN xmlChar * XMLCALL
const xmlChar *add,
int len);
XMLPUBFUN xmlChar * XMLCALL
xmlStrncatNew (const xmlChar *str1,
const xmlChar *str2,
int len);
XMLPUBFUN int XMLCALL
xmlStrPrintf (xmlChar *buf,
int len,
......
......@@ -2462,6 +2462,39 @@ xmlStrncat(xmlChar *cur, const xmlChar *add, int len) {
return(ret);
}
/**
* xmlStrncatNew:
* @str1: first xmlChar string
* @str2: second xmlChar string
* @len: the len of @str2
*
* same as xmlStrncat, but creates a new string. The original
* two strings are not freed.
*
* Returns a new xmlChar * or NULL
*/
xmlChar *
xmlStrncatNew(const xmlChar *str1, const xmlChar *str2, int len) {
int size;
xmlChar *ret;
if ((str2 == NULL) || (len == 0))
return(xmlStrdup(str1));
if (str1 == NULL)
return(xmlStrndup(str2, len));
size = xmlStrlen(str1);
ret = (xmlChar *) xmlMalloc((size + len + 1) * sizeof(xmlChar));
if (ret == NULL) {
xmlErrMemory(NULL, NULL);
return(xmlStrndup(str1, size));
}
memcpy(ret, str1, size * sizeof(xmlChar));
memcpy(&ret[size], str2, len * sizeof(xmlChar));
ret[size + len] = 0;
return(ret);
}
/**
* xmlStrcat:
* @cur: the original xmlChar * array
......
......@@ -5024,7 +5024,9 @@ xmlNodeSetContent(xmlNodePtr cur, const xmlChar *content) {
case XML_PI_NODE:
case XML_COMMENT_NODE:
if (cur->content != NULL) {
xmlFree(cur->content);
if (!((cur->doc != NULL) && (cur->doc->dict != NULL) &&
xmlDictOwns(cur->doc->dict, cur->content)))
xmlFree(cur->content);
}
if (cur->children != NULL) xmlFreeNodeList(cur->children);
cur->last = cur->children = NULL;
......@@ -5172,6 +5174,12 @@ xmlNodeAddContentLen(xmlNodePtr cur, const xmlChar *content, int len) {
case XML_COMMENT_NODE:
case XML_NOTATION_NODE:
if (content != NULL) {
if ((cur->doc != NULL) && (cur->doc->dict != NULL) &&
xmlDictOwns(cur->doc->dict, cur->content)) {
cur->content =
xmlStrncatNew(cur->content, content, len);
break;
}
cur->content = xmlStrncat(cur->content, content, len);
}
case XML_DOCUMENT_NODE:
......@@ -6362,7 +6370,13 @@ xmlTextConcat(xmlNodePtr node, const xmlChar *content, int len) {
#endif
return(-1);
}
node->content = xmlStrncat(node->content, content, len);
/* need to check if content is currently in the dictionary */
if ((node->doc != NULL) && (node->doc->dict != NULL) &&
xmlDictOwns(node->doc->dict, node->content)) {
node->content = xmlStrncatNew(node->content, content, len);
} else {
node->content = xmlStrncat(node->content, content, len);
}
if (node->content == NULL)
return(-1);
return(0);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment