* xmlXPathCompOpEvalToBoolean: * @ctxt: the XPath parser context * * Evaluates if the expression evaluates to true. * * Returns 1 if true, 0 if false and -1 on API or internal errors. */
| 12365 | * Returns 1 if true, 0 if false and -1 on API or internal errors. |
| 12366 | */ |
| 12367 | static int |
| 12368 | xmlXPathCompOpEvalToBoolean(xmlXPathParserContextPtr ctxt, |
| 12369 | xmlXPathStepOpPtr op, |
| 12370 | int isPredicate) |
| 12371 | { |
| 12372 | xmlXPathObjectPtr resObj = NULL; |
| 12373 | |
| 12374 | start: |
| 12375 | if (OP_LIMIT_EXCEEDED(ctxt, 1)) |
| 12376 | return(0); |
| 12377 | /* comp = ctxt->comp; */ |
| 12378 | switch (op->op) { |
| 12379 | case XPATH_OP_END: |
| 12380 | return (0); |
| 12381 | case XPATH_OP_VALUE: |
| 12382 | resObj = (xmlXPathObjectPtr) op->value4; |
| 12383 | if (isPredicate) |
| 12384 | return(xmlXPathEvaluatePredicateResult(ctxt, resObj)); |
| 12385 | return(xmlXPathCastToBoolean(resObj)); |
| 12386 | case XPATH_OP_SORT: |
| 12387 | /* |
| 12388 | * We don't need sorting for boolean results. Skip this one. |
| 12389 | */ |
| 12390 | if (op->ch1 != -1) { |
| 12391 | op = &ctxt->comp->steps[op->ch1]; |
| 12392 | goto start; |
| 12393 | } |
| 12394 | return(0); |
| 12395 | case XPATH_OP_COLLECT: |
| 12396 | if (op->ch1 == -1) |
| 12397 | return(0); |
| 12398 | |
| 12399 | xmlXPathCompOpEval(ctxt, &ctxt->comp->steps[op->ch1]); |
| 12400 | if (ctxt->error != XPATH_EXPRESSION_OK) |
| 12401 | return(-1); |
| 12402 | |
| 12403 | xmlXPathNodeCollectAndTest(ctxt, op, NULL, NULL, 1); |
| 12404 | if (ctxt->error != XPATH_EXPRESSION_OK) |
| 12405 | return(-1); |
| 12406 | |
| 12407 | resObj = valuePop(ctxt); |
| 12408 | if (resObj == NULL) |
| 12409 | return(-1); |
| 12410 | break; |
| 12411 | default: |
| 12412 | /* |
| 12413 | * Fallback to call xmlXPathCompOpEval(). |
| 12414 | */ |
| 12415 | xmlXPathCompOpEval(ctxt, op); |
| 12416 | if (ctxt->error != XPATH_EXPRESSION_OK) |
| 12417 | return(-1); |
| 12418 | |
| 12419 | resObj = valuePop(ctxt); |
| 12420 | if (resObj == NULL) |
| 12421 | return(-1); |
| 12422 | break; |
| 12423 | } |
| 12424 |
no test coverage detected