MCPcopy Create free account
hub / github.com/Kitware/VTK / xmlSAX2TextNode

Function xmlSAX2TextNode

ThirdParty/libxml2/vtklibxml2/SAX2.c:1705–1779  ·  view source on GitHub ↗

* xmlSAX2TextNode: * @ctxt: the parser context * @str: the input string * @len: the string length * * Callback for a text node * * Returns the newly allocated string or NULL if not needed or error */

Source from the content-addressed store, hash-verified

1703 * Returns the newly allocated string or NULL if not needed or error
1704 */
1705static xmlNodePtr
1706xmlSAX2TextNode(xmlParserCtxtPtr ctxt, const xmlChar *str, int len) {
1707 xmlNodePtr ret;
1708 const xmlChar *intern = NULL;
1709
1710 /*
1711 * Allocate
1712 */
1713 if (ctxt->freeElems != NULL) {
1714 ret = ctxt->freeElems;
1715 ctxt->freeElems = ret->next;
1716 ctxt->freeElemsNr--;
1717 } else {
1718 ret = (xmlNodePtr) xmlMalloc(sizeof(xmlNode));
1719 }
1720 if (ret == NULL) {
1721 xmlCtxtErrMemory(ctxt);
1722 return(NULL);
1723 }
1724 memset(ret, 0, sizeof(xmlNode));
1725 /*
1726 * intern the formatting blanks found between tags, or the
1727 * very short strings
1728 */
1729 if (ctxt->dictNames) {
1730 xmlChar cur = str[len];
1731
1732 if ((len < (int) (2 * sizeof(void *))) &&
1733 (ctxt->options & XML_PARSE_COMPACT)) {
1734 /* store the string in the node overriding properties and nsDef */
1735 xmlChar *tmp = (xmlChar *) &(ret->properties);
1736 memcpy(tmp, str, len);
1737 tmp[len] = 0;
1738 intern = tmp;
1739 } else if ((len <= 3) && ((cur == '"') || (cur == '\'') ||
1740 ((cur == '<') && (str[len + 1] != '!')))) {
1741 intern = xmlDictLookup(ctxt->dict, str, len);
1742 if (intern == NULL) {
1743 xmlSAX2ErrMemory(ctxt);
1744 xmlFree(ret);
1745 return(NULL);
1746 }
1747 } else if (IS_BLANK_CH(*str) && (len < 60) && (cur == '<') &&
1748 (str[len + 1] != '!')) {
1749 int i;
1750
1751 for (i = 1;i < len;i++) {
1752 if (!IS_BLANK_CH(str[i])) goto skip;
1753 }
1754 intern = xmlDictLookup(ctxt->dict, str, len);
1755 if (intern == NULL) {
1756 xmlSAX2ErrMemory(ctxt);
1757 xmlFree(ret);
1758 return(NULL);
1759 }
1760 }
1761 }
1762skip:

Callers 2

xmlSAX2AttributeNsFunction · 0.85
xmlSAX2TextFunction · 0.85

Calls 4

xmlCtxtErrMemoryFunction · 0.85
xmlDictLookupFunction · 0.85
xmlSAX2ErrMemoryFunction · 0.85
xmlStrndupFunction · 0.85

Tested by

no test coverage detected