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

Function readPiExp

src/v6/XmlPartReader.js:110–144  ·  view source on GitHub ↗
(parser)

Source from the content-addressed store, hash-verified

108}
109
110export function readPiExp(parser) {
111 let inSingleQuotes = false;
112 let inDoubleQuotes = false;
113 let i;
114 let EOE = false;
115
116 for (i = 0; parser.source.canRead(i) ; i++) {
117 const currentChar = parser.source.readChAt(i);
118 const nextChar = parser.source.readChAt(i+1);
119
120 if (currentChar === "'" && !inDoubleQuotes) {
121 inSingleQuotes = !inSingleQuotes;
122 } else if (currentChar === '"' && !inSingleQuotes) {
123 inDoubleQuotes = !inDoubleQuotes;
124 }
125
126 if (!inSingleQuotes && !inDoubleQuotes) {
127 if (currentChar === '?' && nextChar === '>') {
128 EOE = true;
129 break; // Exit the loop when '?>' is found
130 }
131 }
132 }
133 if(inSingleQuotes || inDoubleQuotes){
134 throw new Error("Invalid attribute expression. Quote is not properly closed in PI tag expression");
135 }else if(!EOE) throw new Error("Unexpected closing of source. Waiting for '?>'");
136
137 if(!parser.options.attributes.ignore){
138 //TODO: use regex to verify attributes if not set to ignore
139 }
140
141 const exp = parser.source.readStr(i);
142 parser.source.updateBufferBoundary(i + 1);
143 return buildTagExpObj(exp, parser)
144}
145
146function buildTagExpObj(exp, parser){
147 const tagExp = {

Callers 1

readPiTagFunction · 0.90

Calls 5

buildTagExpObjFunction · 0.85
canReadMethod · 0.45
readChAtMethod · 0.45
readStrMethod · 0.45
updateBufferBoundaryMethod · 0.45

Tested by

no test coverage detected