| 490 | } |
| 491 | |
| 492 | bool |
| 493 | EsiParser::_processTryTag(const string &data, size_t curr_pos, size_t end_pos, DocNodeList &node_list) const |
| 494 | { |
| 495 | const char *data_start_ptr = data.data() + curr_pos; |
| 496 | int data_size = end_pos - curr_pos; |
| 497 | DocNode try_node(DocNode::TYPE_TRY); |
| 498 | if (!parse(try_node.child_nodes, data_start_ptr, data_size)) { |
| 499 | TSError("[%s] Could not parse try node's content", __FUNCTION__); |
| 500 | return false; |
| 501 | } |
| 502 | |
| 503 | DocNodeList::iterator iter, end_node, attempt_node, except_node, temp_iter; |
| 504 | end_node = try_node.child_nodes.end(); |
| 505 | attempt_node = except_node = end_node; |
| 506 | iter = try_node.child_nodes.begin(); |
| 507 | while (iter != end_node) { |
| 508 | if (iter->type == DocNode::TYPE_ATTEMPT) { |
| 509 | if (attempt_node != end_node) { |
| 510 | TSError("[%s] Can have exactly one attempt node in try block", __FUNCTION__); |
| 511 | return false; |
| 512 | } |
| 513 | attempt_node = iter; |
| 514 | } else if (iter->type == DocNode::TYPE_EXCEPT) { |
| 515 | if (except_node != end_node) { |
| 516 | TSError("[%s] Can have exactly one except node in try block", __FUNCTION__); |
| 517 | return false; |
| 518 | } |
| 519 | except_node = iter; |
| 520 | } else if (iter->type == DocNode::TYPE_PRE) { |
| 521 | if (!_isWhitespace(iter->data, iter->data_len)) { |
| 522 | TSError("[%s] Cannot have non-whitespace raw text as top level node in try block", __FUNCTION__); |
| 523 | return false; |
| 524 | } |
| 525 | Dbg(dbg_ctl, "[%s] Ignoring top-level whitespace raw text", __FUNCTION__); |
| 526 | temp_iter = iter; |
| 527 | ++temp_iter; |
| 528 | try_node.child_nodes.erase(iter); |
| 529 | iter = temp_iter; |
| 530 | continue; // skip the increment |
| 531 | } else { |
| 532 | TSError("[%s] Only attempt/except/text nodes allowed in try block; [%s] node invalid", __FUNCTION__, |
| 533 | DocNode::type_names_[iter->type]); |
| 534 | return false; |
| 535 | } |
| 536 | ++iter; |
| 537 | } |
| 538 | if ((attempt_node == end_node) || (except_node == end_node)) { |
| 539 | TSError("[%s] try block must contain one each of attempt and except nodes", __FUNCTION__); |
| 540 | return false; |
| 541 | } |
| 542 | node_list.push_back(try_node); |
| 543 | Dbg(dbg_ctl, "[%s] Added try node successfully", __FUNCTION__); |
| 544 | return true; |
| 545 | } |
| 546 | |
| 547 | bool |
| 548 | EsiParser::_processChooseTag(const string &data, size_t curr_pos, size_t end_pos, DocNodeList &node_list) const |