42 static abool bAttNameLookup(
xml* spXml, uint32_t* uipName, uint32_t uiLen);
43 static att_decl* spElNameLookup(
xml* spXml, uint32_t* uipEName, uint32_t uiELen);
45 static uint8_t s_ucRightBracket = 93;
55 uint32_t* uipChars = (uint32_t*)
vpVecFirst(spXml->vpVec32);
56 uint32_t* uipName = uipChars + spF->sSName.uiOffset;
57 att_decl* spDecl = spElNameLookup(spXml, uipName, spF->sSName.uiLength);
61 for(; spDecl < spEnd; spDecl++){
80 spXml->spCurrentFrame->sSName.uiOffset =
uiVecLen(spXml->vpVec32);
81 spXml->spCurrentFrame->sSName.uiLength = (uint32_t)uiLen;
88 XML_THROW(
"Tag names beginning with \"xml:\" are reserved - Extensible Markup Language (XML) 1.0 (Fifth Edition) errata\n"
89 "https://www.w3.org/XML/xml-V10-5e-errata");
95 if(spXml->pfnEmptyTagCallback){
98 spXml->spCurrentFrame->uiAttCount, spXml->vpEmptyTagData);
106 if(spXml->pfnStartTagCallback){
109 spXml->spCurrentFrame->uiAttCount, spXml->vpStartTagData);
113 spXml->spCurrentFrame->sContent.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
114 spXml->spCurrentFrame->sContent.uiLength = 0;
124 uint32_t uiELen = (uint32_t)
uiVecLen(spXml->vpVecName);
125 uint32_t* uipEName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
126 uint32_t* uipSName = (uint32_t*)
vpVecAt(spXml->vpVec32, spF->sSName.uiOffset);
127 uint32_t uiSLen = spF->sSName.uiLength;
128 if(!
bCompNames(uipSName, uiSLen, uipEName, uiELen)){
129 XML_THROW(
"Well-formedness constraint: Element Type Match\n"
130 "The Name in an element's end-tag MUST match the element type in the start-tag.");
132 spF->sContent.uiLength = (uint32_t)
uiVecLen(spXml->vpVec32) - spF->sContent.uiOffset;
135 spF->sEName.uiOffset = (uint32_t)
uiVecLen(spXml->vpVec32);
136 spF->sEName.uiLength = uiELen;
138 if(spXml->pfnEndTagCallback){
143 spXml->pfnEndTagCallback(&sName, &sContent, spXml->vpEndTagData);
163 if(bAttNameLookup(spXml, (uint32_t*)
vpVecFirst(spXml->vpVecName), (uint32_t)uiNameLen)){
164 XML_THROW(
"Well-formedness constraint: Unique Att Spec\n"
165 "An attribute name MUST NOT appear more than once in the same start-tag or empty-element tag.");
180 spNv->sValue.uiLength = (uint32_t)(
uiVecLen(spXml->vpVec32) - spNv->sValue.uiOffset);
181 spXml->spCurrentFrame->uiAttCount++;
184 uint32_t* uipData = (uint32_t*)
vpVecFirst(spXml->vpVec32) + spNv->sValue.uiOffset;
185 uint32_t* uipDataEnd = uipData + spNv->sValue.uiLength;
186 for(; uipData < uipDataEnd; uipData++){
188 XML_THROW(
"Well-formedness constraint: No < in Attribute Values\n"
189 "The replacement text of any entity referred to directly or indirectly in an attribute value MUST NOT contain a <.");
197 vpVecPush(spXml->vpVec32, &spXml->uiChar);
204 if((spXml->uiChar == 9) || (spXml->uiChar == 10) || (spXml->uiChar == 13)){
213 uint32_t* uipName = (uint32_t*)
vpVecFirst(spXml->vpVecName);
214 uint32_t uiNameLen = (uint32_t)
uiVecLen(spXml->vpVecName);
217 XML_THROW(
"Well-formedness constraint: Entity Declared\n"
218 "The replacement text of any entity referred to directly or indirectly in an attribute value MUST NOT contain a <.");
234 uint32_t uiSum, uiDigit;
236 for(ui = 0; ui < spData->uiParserPhraseLength; ui++, acpChar++){
237 uiDigit = *acpChar - 48;
239 XML_THROW(
"decimal value in Reference is too large: causes uint32_t overflow");
241 if(!
bSum32(uiSum, uiDigit, &uiSum)){
242 XML_THROW(
"decimal value in Reference is too large: causes uint32_t overflow");
247 snprintf(caBuf,
CABUF_LEN,
"Well-formedness Constraint: Legal Character\n"
248 "Characters referred to using character references MUST match the production for Char\n"
249 "https://www.w3.org/TR/REC-xml/#sec-references\n"
250 "decimal character: %u", uiSum);
253 spXml->uiChar = uiSum;
256 XML_THROW(
"decimal character reference error");
266 uint32_t uiDigit = 0;
267 for(ui = 0; ui < spData->uiParserPhraseLength; ui++, acpChar++){
268 if(*acpChar >= 48 && *acpChar <= 57){
269 uiDigit = *acpChar - 48;
270 }
else if(*acpChar >= 65 && *acpChar <= 70){
271 uiDigit = *acpChar - 55;
272 }
else if(*acpChar >= 97 && *acpChar <= 102){
273 uiDigit = *acpChar - 87;
275 snprintf(caBuf,
CABUF_LEN,
"illegal hex digit in Reference: %c", *(
char*)acpChar);
279 XML_THROW(
"hex value in Reference is too large: causes 32-bit overflow");
281 if(!
bSum32(uiSum, uiDigit, &uiSum)){
282 XML_THROW(
"hex value in Reference is too large: causes 32-bit overflow");
287 snprintf(caBuf,
CABUF_LEN,
"Well-formedness Constraint: Legal Character\n"
288 "Characters referred to using character references MUST match the production for Char\n"
289 "https://www.w3.org/TR/REC-xml/#sec-references\n"
290 "hex character: 0x%X", uiSum);
293 spXml->uiChar = uiSum;
296 XML_THROW(
"hex character reference error");
306 static abool bAttNameLookup(
xml* spXml, uint32_t* uipName, uint32_t uiLen){
307 if(spXml->spCurrentFrame->uiAttCount){
308 uint32_t* uipChars = (uint32_t*)
vpVecFirst(spXml->vpVec32);
312 named_value* spEnd = spValue + spXml->spCurrentFrame->uiAttCount;
313 for(; spValue < spEnd; spValue++){
316 if(
bCompNames(uipLName, uiLLen, uipName, uiLen)){
323 static att_decl* spElNameLookup(
xml* spXml, uint32_t* uipEName, uint32_t uiELen){
326 uint32_t* uipChars = (uint32_t*)
vpVecFirst(spXml->vpVec32);
329 for(; spDecl < spEnd; spDecl++){
344 vpVecPush(spXml->vpVec32, &spXml->uiChar);
350 XML_THROW(
"\"]]>\" not allowed in content character data");
378 XML_THROW(
"expected end of CDATA section ']]>' not found");
384 vpVecPush(spXml->vpVec32, &s_ucRightBracket);
385 vpVecPush(spXml->vpVec32, &spXml->uiChar);
391 vpVecPush(spXml->vpVec32, &s_ucRightBracket);
392 vpVecPush(spXml->vpVec32, &s_ucRightBracket);
393 vpVecPush(spXml->vpVec32, &spXml->uiChar);