MCPcopy Create free account
hub / github.com/NaturalIntelligence/fast-xml-parser / readStopNodeData

Function readStopNodeData

src/xmlparser/OrderedObjParser.js:753–800  ·  view source on GitHub ↗

* find paired tag for a stop node * @param {string} xmlData * @param {string} tagName * @param {number} i

(xmlData, tagName, i)

Source from the content-addressed store, hash-verified

751 * @param {number} i
752 */
753function readStopNodeData(xmlData, tagName, i) {
754 const startIndex = i;
755 // Starting at 1 since we already have an open tag
756 let openTagCount = 1;
757
758 const xmllen = xmlData.length;
759 for (; i < xmllen; i++) {
760 if (xmlData[i] === "<") {
761 const c1 = xmlData.charCodeAt(i + 1);
762 if (c1 === 47) {//close tag '/'
763 const closeIndex = findClosingChar(xmlData, ">", i, `${tagName} is not closed`);
764 let closeTagName = xmlData.substring(i + 2, closeIndex).trim();
765 if (closeTagName === tagName) {
766 openTagCount--;
767 if (openTagCount === 0) {
768 return {
769 tagContent: xmlData.substring(startIndex, i),
770 i: closeIndex
771 }
772 }
773 }
774 i = closeIndex;
775 } else if (c1 === 63) { //?
776 const closeIndex = findClosingIndex(xmlData, "?>", i + 1, "StopNode is not closed.")
777 i = closeIndex;
778 } else if (c1 === 33
779 && xmlData.charCodeAt(i + 2) === 45
780 && xmlData.charCodeAt(i + 3) === 45) { // '!--'
781 const closeIndex = findClosingIndex(xmlData, "-->", i + 3, "StopNode is not closed.")
782 i = closeIndex;
783 } else if (c1 === 33
784 && xmlData.charCodeAt(i + 2) === 91) { // '!['
785 const closeIndex = findClosingIndex(xmlData, "]]>", i, "StopNode is not closed.") - 2;
786 i = closeIndex;
787 } else {
788 const tagData = readTagExp(xmlData, i, false)
789
790 if (tagData) {
791 const openTagName = tagData && tagData.tagName;
792 if (openTagName === tagName && tagData.tagExp[tagData.tagExp.length - 1] !== "/") {
793 openTagCount++;
794 }
795 i = tagData.closeIndex;
796 }
797 }
798 }
799 }//end for loop
800}
801
802function parseValue(val, shouldParse, options) {
803 if (shouldParse && typeof val === 'string') {

Callers

nothing calls this directly

Calls 3

findClosingCharFunction · 0.85
findClosingIndexFunction · 0.85
readTagExpFunction · 0.70

Tested by

no test coverage detected