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

Function xmlSAX2Text

ThirdParty/libxml2/vtklibxml2/SAX2.c:2387–2518  ·  view source on GitHub ↗

* xmlSAX2Text: * @ctx: the user data (XML parser context) * @ch: a xmlChar string * @len: the number of xmlChar * @type: text or cdata * * Append characters. */

Source from the content-addressed store, hash-verified

2385 * Append characters.
2386 */
2387static void
2388xmlSAX2Text(xmlParserCtxtPtr ctxt, const xmlChar *ch, int len,
2389 xmlElementType type)
2390{
2391 xmlNodePtr lastChild;
2392
2393 if (ctxt == NULL) return;
2394 /*
2395 * Handle the data if any. If there is no child
2396 * add it as content, otherwise if the last child is text,
2397 * concatenate it, else create a new node of type text.
2398 */
2399
2400 if (ctxt->node == NULL) {
2401 return;
2402 }
2403 lastChild = ctxt->node->last;
2404
2405 /*
2406 * Here we needed an accelerator mechanism in case of very large
2407 * elements. Use an attribute in the structure !!!
2408 */
2409 if (lastChild == NULL) {
2410 if (type == XML_TEXT_NODE)
2411 lastChild = xmlSAX2TextNode(ctxt, ch, len);
2412 else
2413 lastChild = xmlNewCDataBlock(ctxt->myDoc, ch, len);
2414 if (lastChild != NULL) {
2415 ctxt->node->children = lastChild;
2416 ctxt->node->last = lastChild;
2417 lastChild->parent = ctxt->node;
2418 lastChild->doc = ctxt->node->doc;
2419 ctxt->nodelen = len;
2420 ctxt->nodemem = len + 1;
2421 } else {
2422 xmlSAX2ErrMemory(ctxt);
2423 return;
2424 }
2425 } else {
2426 int coalesceText = (lastChild != NULL) &&
2427 (lastChild->type == type) &&
2428 ((type != XML_TEXT_NODE) ||
2429 (lastChild->name == xmlStringText));
2430 if ((coalesceText) && (ctxt->nodemem != 0)) {
2431 int maxLength = (ctxt->options & XML_PARSE_HUGE) ?
2432 XML_MAX_HUGE_LENGTH :
2433 XML_MAX_TEXT_LENGTH;
2434
2435 /*
2436 * The whole point of maintaining nodelen and nodemem,
2437 * xmlTextConcat is too costly, i.e. compute length,
2438 * reallocate a new buffer, move data, append ch. Here
2439 * We try to minimize realloc() uses and avoid copying
2440 * and recomputing length over and over.
2441 */
2442 if (lastChild->content == (xmlChar *)&(lastChild->properties)) {
2443 lastChild->content = xmlStrdup(lastChild->content);
2444 lastChild->properties = NULL;

Callers 2

xmlSAX2CharactersFunction · 0.85
xmlSAX2CDataBlockFunction · 0.85

Calls 10

xmlSAX2TextNodeFunction · 0.85
xmlNewCDataBlockFunction · 0.85
xmlSAX2ErrMemoryFunction · 0.85
xmlStrdupFunction · 0.85
xmlDictOwnsFunction · 0.85
xmlFatalErrFunction · 0.85
xmlHaltParserFunction · 0.85
xmlTextConcatFunction · 0.85
xmlStrlenFunction · 0.85
xmlSAX2AppendChildFunction · 0.85

Tested by

no test coverage detected