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

Function xmlEncodeEntitiesInternal

ThirdParty/libxml2/vtklibxml2/entities.c:541–697  ·  view source on GitHub ↗

* xmlEncodeEntitiesInternal: * @doc: the document containing the string * @input: A string to convert to XML. * @attr: are we handling an attribute value * * Do a global encoding of a string, replacing the predefined entities * and non ASCII values with their entities and CharRef counterparts. * Contrary to xmlEncodeEntities, this routine is reentrant, and result * must be deallocated.

Source from the content-addressed store, hash-verified

539 * Returns A newly allocated string with the substitution done.
540 */
541static xmlChar *
542xmlEncodeEntitiesInternal(xmlDocPtr doc, const xmlChar *input, int attr) {
543 const xmlChar *cur = input;
544 xmlChar *buffer = NULL;
545 xmlChar *out = NULL;
546 size_t buffer_size = 0;
547 int html = 0;
548
549 if (input == NULL) return(NULL);
550 if (doc != NULL)
551 html = (doc->type == XML_HTML_DOCUMENT_NODE);
552
553 /*
554 * allocate an translation buffer.
555 */
556 buffer_size = 1000;
557 buffer = (xmlChar *) xmlMalloc(buffer_size);
558 if (buffer == NULL)
559 return(NULL);
560 out = buffer;
561
562 while (*cur != '\0') {
563 size_t indx = out - buffer;
564 if (indx + 100 > buffer_size) {
565
566 growBufferReentrant();
567 out = &buffer[indx];
568 }
569
570 /*
571 * By default one have to encode at least '<', '>', '"' and '&' !
572 */
573 if (*cur == '<') {
574 const xmlChar *end;
575
576 /*
577 * Special handling of server side include in HTML attributes
578 */
579 if (html && attr &&
580 (cur[1] == '!') && (cur[2] == '-') && (cur[3] == '-') &&
581 ((end = xmlStrstr(cur, BAD_CAST "-->")) != NULL)) {
582 while (cur != end) {
583 *out++ = *cur++;
584 indx = out - buffer;
585 if (indx + 100 > buffer_size) {
586 growBufferReentrant();
587 out = &buffer[indx];
588 }
589 }
590 *out++ = *cur++;
591 *out++ = *cur++;
592 *out++ = *cur++;
593 continue;
594 }
595 *out++ = '&';
596 *out++ = 'l';
597 *out++ = 't';
598 *out++ = ';';

Callers 2

Calls 2

xmlStrstrFunction · 0.85
xmlGetUTF8CharFunction · 0.85

Tested by

no test coverage detected