1
0
mirror of https://gitlab.gnome.org/GNOME/libxml2.git synced 2025-07-29 11:41:22 +03:00

Reduce indentation in HTMLparser.c

No functional change.
This commit is contained in:
Nick Wellnhofer
2022-07-15 13:26:41 +02:00
parent 39745c927a
commit 6722d22c88

View File

@ -4378,72 +4378,72 @@ htmlParseContent(htmlParserCtxtPtr ctxt) {
* Handle SCRIPT/STYLE separately * Handle SCRIPT/STYLE separately
*/ */
htmlParseScript(ctxt); htmlParseScript(ctxt);
} else {
/*
* Sometimes DOCTYPE arrives in the middle of the document
*/
if ((CUR == '<') && (NXT(1) == '!') &&
(UPP(2) == 'D') && (UPP(3) == 'O') &&
(UPP(4) == 'C') && (UPP(5) == 'T') &&
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"Misplaced DOCTYPE declaration\n",
BAD_CAST "DOCTYPE" , NULL);
htmlParseDocTypeDecl(ctxt);
}
/*
* First case : a comment
*/
if ((CUR == '<') && (NXT(1) == '!') &&
(NXT(2) == '-') && (NXT(3) == '-')) {
htmlParseComment(ctxt);
}
/*
* Second case : a Processing Instruction.
*/
else if ((CUR == '<') && (NXT(1) == '?')) {
htmlParsePI(ctxt);
}
/*
* Third case : a sub-element.
*/
else if ((CUR == '<') && IS_ASCII_LETTER(NXT(1))) {
htmlParseElement(ctxt);
}
else if (CUR == '<') {
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, BAD_CAST "<", 1);
NEXT;
}
/*
* Fourth case : a reference. If if has not been resolved,
* parsing returns it's Name, create the node
*/
else if (CUR == '&') {
htmlParseReference(ctxt);
}
/*
* Fifth case : end of the resource
*/
else if (CUR == 0) {
htmlAutoCloseOnEnd(ctxt);
break;
}
/*
* Last case, text. Note that References are handled directly.
*/
else {
htmlParseCharData(ctxt);
}
} }
/*
* Sometimes DOCTYPE arrives in the middle of the document
*/
else if ((CUR == '<') && (NXT(1) == '!') &&
(UPP(2) == 'D') && (UPP(3) == 'O') &&
(UPP(4) == 'C') && (UPP(5) == 'T') &&
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"Misplaced DOCTYPE declaration\n",
BAD_CAST "DOCTYPE" , NULL);
htmlParseDocTypeDecl(ctxt);
}
/*
* First case : a comment
*/
else if ((CUR == '<') && (NXT(1) == '!') &&
(NXT(2) == '-') && (NXT(3) == '-')) {
htmlParseComment(ctxt);
}
/*
* Second case : a Processing Instruction.
*/
else if ((CUR == '<') && (NXT(1) == '?')) {
htmlParsePI(ctxt);
}
/*
* Third case : a sub-element.
*/
else if ((CUR == '<') && IS_ASCII_LETTER(NXT(1))) {
htmlParseElement(ctxt);
}
else if (CUR == '<') {
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, BAD_CAST "<", 1);
NEXT;
}
/*
* Fourth case : a reference. If if has not been resolved,
* parsing returns it's Name, create the node
*/
else if (CUR == '&') {
htmlParseReference(ctxt);
}
/*
* Fifth case : end of the resource
*/
else if (CUR == 0) {
htmlAutoCloseOnEnd(ctxt);
break;
}
/*
* Last case, text. Note that References are handled directly.
*/
else {
htmlParseCharData(ctxt);
}
GROW; GROW;
} }
if (currentNode != NULL) xmlFree(currentNode); if (currentNode != NULL) xmlFree(currentNode);
@ -4783,76 +4783,76 @@ htmlParseContentInternal(htmlParserCtxtPtr ctxt) {
* Handle SCRIPT/STYLE separately * Handle SCRIPT/STYLE separately
*/ */
htmlParseScript(ctxt); htmlParseScript(ctxt);
} else {
/*
* Sometimes DOCTYPE arrives in the middle of the document
*/
if ((CUR == '<') && (NXT(1) == '!') &&
(UPP(2) == 'D') && (UPP(3) == 'O') &&
(UPP(4) == 'C') && (UPP(5) == 'T') &&
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"Misplaced DOCTYPE declaration\n",
BAD_CAST "DOCTYPE" , NULL);
htmlParseDocTypeDecl(ctxt);
}
/*
* First case : a comment
*/
if ((CUR == '<') && (NXT(1) == '!') &&
(NXT(2) == '-') && (NXT(3) == '-')) {
htmlParseComment(ctxt);
}
/*
* Second case : a Processing Instruction.
*/
else if ((CUR == '<') && (NXT(1) == '?')) {
htmlParsePI(ctxt);
}
/*
* Third case : a sub-element.
*/
else if ((CUR == '<') && IS_ASCII_LETTER(NXT(1))) {
htmlParseElementInternal(ctxt);
if (currentNode != NULL) xmlFree(currentNode);
currentNode = xmlStrdup(ctxt->name);
depth = ctxt->nameNr;
}
else if (CUR == '<') {
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, BAD_CAST "<", 1);
NEXT;
}
/*
* Fourth case : a reference. If if has not been resolved,
* parsing returns it's Name, create the node
*/
else if (CUR == '&') {
htmlParseReference(ctxt);
}
/*
* Fifth case : end of the resource
*/
else if (CUR == 0) {
htmlAutoCloseOnEnd(ctxt);
break;
}
/*
* Last case, text. Note that References are handled directly.
*/
else {
htmlParseCharData(ctxt);
}
} }
/*
* Sometimes DOCTYPE arrives in the middle of the document
*/
else if ((CUR == '<') && (NXT(1) == '!') &&
(UPP(2) == 'D') && (UPP(3) == 'O') &&
(UPP(4) == 'C') && (UPP(5) == 'T') &&
(UPP(6) == 'Y') && (UPP(7) == 'P') &&
(UPP(8) == 'E')) {
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
"Misplaced DOCTYPE declaration\n",
BAD_CAST "DOCTYPE" , NULL);
htmlParseDocTypeDecl(ctxt);
}
/*
* First case : a comment
*/
else if ((CUR == '<') && (NXT(1) == '!') &&
(NXT(2) == '-') && (NXT(3) == '-')) {
htmlParseComment(ctxt);
}
/*
* Second case : a Processing Instruction.
*/
else if ((CUR == '<') && (NXT(1) == '?')) {
htmlParsePI(ctxt);
}
/*
* Third case : a sub-element.
*/
else if ((CUR == '<') && IS_ASCII_LETTER(NXT(1))) {
htmlParseElementInternal(ctxt);
if (currentNode != NULL) xmlFree(currentNode);
currentNode = xmlStrdup(ctxt->name);
depth = ctxt->nameNr;
}
else if (CUR == '<') {
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, BAD_CAST "<", 1);
NEXT;
}
/*
* Fourth case : a reference. If if has not been resolved,
* parsing returns it's Name, create the node
*/
else if (CUR == '&') {
htmlParseReference(ctxt);
}
/*
* Fifth case : end of the resource
*/
else if (CUR == 0) {
htmlAutoCloseOnEnd(ctxt);
break;
}
/*
* Last case, text. Note that References are handled directly.
*/
else {
htmlParseCharData(ctxt);
}
GROW; GROW;
} }
if (currentNode != NULL) xmlFree(currentNode); if (currentNode != NULL) xmlFree(currentNode);
@ -5949,93 +5949,91 @@ htmlParseTryOrFinish(htmlParserCtxtPtr ctxt, int terminate) {
#endif #endif
break; break;
} }
} else { } else if ((cur == '<') && (next == '!') &&
/* (UPP(2) == 'D') && (UPP(3) == 'O') &&
* Sometimes DOCTYPE arrives in the middle of the document (UPP(4) == 'C') && (UPP(5) == 'T') &&
*/ (UPP(6) == 'Y') && (UPP(7) == 'P') &&
if ((cur == '<') && (next == '!') && (UPP(8) == 'E')) {
(UPP(2) == 'D') && (UPP(3) == 'O') && /*
(UPP(4) == 'C') && (UPP(5) == 'T') && * Sometimes DOCTYPE arrives in the middle of the document
(UPP(6) == 'Y') && (UPP(7) == 'P') && */
(UPP(8) == 'E')) { if ((!terminate) &&
if ((!terminate) && (htmlParseLookupSequence(ctxt, '>', 0, 0, 1) < 0))
(htmlParseLookupSequence(ctxt, '>', 0, 0, 1) < 0)) goto done;
goto done; htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR,
htmlParseErr(ctxt, XML_HTML_STRUCURE_ERROR, "Misplaced DOCTYPE declaration\n",
"Misplaced DOCTYPE declaration\n", BAD_CAST "DOCTYPE" , NULL);
BAD_CAST "DOCTYPE" , NULL); htmlParseDocTypeDecl(ctxt);
htmlParseDocTypeDecl(ctxt); } else if ((cur == '<') && (next == '!') &&
} else if ((cur == '<') && (next == '!') && (in->cur[2] == '-') && (in->cur[3] == '-')) {
(in->cur[2] == '-') && (in->cur[3] == '-')) { if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0))
if ((!terminate) && (htmlParseLookupCommentEnd(ctxt) < 0)) goto done;
goto done;
#ifdef DEBUG_PUSH #ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"HPP: Parsing Comment\n"); "HPP: Parsing Comment\n");
#endif #endif
htmlParseComment(ctxt); htmlParseComment(ctxt);
ctxt->instate = XML_PARSER_CONTENT; ctxt->instate = XML_PARSER_CONTENT;
} else if ((cur == '<') && (next == '?')) { } else if ((cur == '<') && (next == '?')) {
if ((!terminate) && if ((!terminate) &&
(htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0)) (htmlParseLookupSequence(ctxt, '>', 0, 0, 0) < 0))
goto done; goto done;
#ifdef DEBUG_PUSH #ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"HPP: Parsing PI\n"); "HPP: Parsing PI\n");
#endif #endif
htmlParsePI(ctxt); htmlParsePI(ctxt);
ctxt->instate = XML_PARSER_CONTENT; ctxt->instate = XML_PARSER_CONTENT;
} else if ((cur == '<') && (next == '!') && (avail < 4)) { } else if ((cur == '<') && (next == '!') && (avail < 4)) {
goto done; goto done;
} else if ((cur == '<') && (next == '/')) { } else if ((cur == '<') && (next == '/')) {
ctxt->instate = XML_PARSER_END_TAG; ctxt->instate = XML_PARSER_END_TAG;
ctxt->checkIndex = 0; ctxt->checkIndex = 0;
#ifdef DEBUG_PUSH #ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"HPP: entering END_TAG\n"); "HPP: entering END_TAG\n");
#endif #endif
break; break;
} else if ((cur == '<') && IS_ASCII_LETTER(next)) { } else if ((cur == '<') && IS_ASCII_LETTER(next)) {
if ((!terminate) && (next == 0)) if ((!terminate) && (next == 0))
goto done; goto done;
ctxt->instate = XML_PARSER_START_TAG; ctxt->instate = XML_PARSER_START_TAG;
ctxt->checkIndex = 0; ctxt->checkIndex = 0;
#ifdef DEBUG_PUSH #ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"HPP: entering START_TAG\n"); "HPP: entering START_TAG\n");
#endif #endif
break; break;
} else if (cur == '<') { } else if (cur == '<') {
if ((ctxt->sax != NULL) && (!ctxt->disableSAX) && if ((ctxt->sax != NULL) && (!ctxt->disableSAX) &&
(ctxt->sax->characters != NULL)) (ctxt->sax->characters != NULL))
ctxt->sax->characters(ctxt->userData, ctxt->sax->characters(ctxt->userData,
BAD_CAST "<", 1); BAD_CAST "<", 1);
NEXT; NEXT;
} else { } else {
/* /*
* check that the text sequence is complete * check that the text sequence is complete
* before handing out the data to the parser * before handing out the data to the parser
* to avoid problems with erroneous end of * to avoid problems with erroneous end of
* data detection. * data detection.
*/ */
if ((!terminate) && if ((!terminate) &&
(htmlParseLookupSequence(ctxt, '<', 0, 0, 0) < 0)) (htmlParseLookupSequence(ctxt, '<', 0, 0, 0) < 0))
goto done; goto done;
ctxt->checkIndex = 0; ctxt->checkIndex = 0;
#ifdef DEBUG_PUSH #ifdef DEBUG_PUSH
xmlGenericError(xmlGenericErrorContext, xmlGenericError(xmlGenericErrorContext,
"HPP: Parsing char data\n"); "HPP: Parsing char data\n");
#endif #endif
while ((ctxt->instate != XML_PARSER_EOF) && while ((ctxt->instate != XML_PARSER_EOF) &&
(cur != '<') && (in->cur < in->end)) { (cur != '<') && (in->cur < in->end)) {
if (cur == '&') { if (cur == '&') {
htmlParseReference(ctxt); htmlParseReference(ctxt);
} else { } else {
htmlParseCharData(ctxt); htmlParseCharData(ctxt);
}
cur = in->cur[0];
} }
} cur = in->cur[0];
}
} }
break; break;