* xmlPatMatch: * @comp: the precompiled pattern * @node: a node * * Test whether the node matches the pattern * * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure */
| 495 | * Returns 1 if it matches, 0 if it doesn't and -1 in case of failure |
| 496 | */ |
| 497 | static int |
| 498 | xmlPatMatch(xmlPatternPtr comp, xmlNodePtr node) { |
| 499 | int i; |
| 500 | xmlStepOpPtr step; |
| 501 | xmlStepStates states = {0, 0, NULL}; /* // may require backtrack */ |
| 502 | |
| 503 | if ((comp == NULL) || (node == NULL)) return(-1); |
| 504 | i = 0; |
| 505 | restart: |
| 506 | for (;i < comp->nbStep;i++) { |
| 507 | step = &comp->steps[i]; |
| 508 | switch (step->op) { |
| 509 | case XML_OP_END: |
| 510 | goto found; |
| 511 | case XML_OP_ROOT: |
| 512 | if (node->type == XML_NAMESPACE_DECL) |
| 513 | goto rollback; |
| 514 | node = node->parent; |
| 515 | if ((node->type == XML_DOCUMENT_NODE) || |
| 516 | (node->type == XML_HTML_DOCUMENT_NODE)) |
| 517 | continue; |
| 518 | goto rollback; |
| 519 | case XML_OP_ELEM: |
| 520 | if (node->type != XML_ELEMENT_NODE) |
| 521 | goto rollback; |
| 522 | if (step->value == NULL) |
| 523 | continue; |
| 524 | if (step->value[0] != node->name[0]) |
| 525 | goto rollback; |
| 526 | if (!xmlStrEqual(step->value, node->name)) |
| 527 | goto rollback; |
| 528 | |
| 529 | /* Namespace test */ |
| 530 | if (node->ns == NULL) { |
| 531 | if (step->value2 != NULL) |
| 532 | goto rollback; |
| 533 | } else if (node->ns->href != NULL) { |
| 534 | if (step->value2 == NULL) |
| 535 | goto rollback; |
| 536 | if (!xmlStrEqual(step->value2, node->ns->href)) |
| 537 | goto rollback; |
| 538 | } |
| 539 | continue; |
| 540 | case XML_OP_CHILD: { |
| 541 | xmlNodePtr lst; |
| 542 | |
| 543 | if ((node->type != XML_ELEMENT_NODE) && |
| 544 | (node->type != XML_DOCUMENT_NODE) && |
| 545 | (node->type != XML_HTML_DOCUMENT_NODE)) |
| 546 | goto rollback; |
| 547 | |
| 548 | lst = node->children; |
| 549 | |
| 550 | if (step->value != NULL) { |
| 551 | while (lst != NULL) { |
| 552 | if ((lst->type == XML_ELEMENT_NODE) && |
| 553 | (step->value[0] == lst->name[0]) && |
| 554 | (xmlStrEqual(step->value, lst->name))) |
no test coverage detected