| 539 | } |
| 540 | |
| 541 | bool |
| 542 | EsiProcessor::_handleChoose(DocNodeList::iterator &curr_node) |
| 543 | { |
| 544 | DocNodeList::iterator iter, otherwise_node, winning_node, end_node; |
| 545 | end_node = curr_node->child_nodes.end(); |
| 546 | otherwise_node = end_node; |
| 547 | for (iter = curr_node->child_nodes.begin(); iter != end_node; ++iter) { |
| 548 | if (iter->type == DocNode::TYPE_OTHERWISE) { |
| 549 | otherwise_node = iter; |
| 550 | break; |
| 551 | } |
| 552 | } |
| 553 | winning_node = end_node; |
| 554 | for (iter = curr_node->child_nodes.begin(); iter != end_node; ++iter) { |
| 555 | if (iter->type == DocNode::TYPE_WHEN) { |
| 556 | const Attribute &test_expr = iter->attr_list.front(); |
| 557 | if (_expression.evaluate(test_expr.value, test_expr.value_len)) { |
| 558 | winning_node = iter; |
| 559 | break; |
| 560 | } |
| 561 | } |
| 562 | } |
| 563 | if (winning_node == end_node) { |
| 564 | DBG("[%s] All when nodes failed to evaluate to true", __FUNCTION__); |
| 565 | if (otherwise_node != end_node) { |
| 566 | DBG("[%s] Using otherwise node...", __FUNCTION__); |
| 567 | winning_node = otherwise_node; |
| 568 | } else { |
| 569 | DBG("[%s] No otherwise node, nothing to do...", __FUNCTION__); |
| 570 | return true; |
| 571 | } |
| 572 | } |
| 573 | // splice() inserts elements *before* given position, but we need to |
| 574 | // insert new nodes after the choose node for them to be seen by |
| 575 | // preprocess(); hence... |
| 576 | DocNodeList::iterator next_node = curr_node; |
| 577 | ++next_node; |
| 578 | _node_list.splice(next_node, winning_node->child_nodes); |
| 579 | return true; |
| 580 | } |
| 581 | |
| 582 | bool |
| 583 | EsiProcessor::_handleTry(DocNodeList::iterator &curr_node) |