Public Methods | |
cmt_one_more (cmt_node* n) | |
const cmt_regexp::iterator | match (const cmt_string& text, int pos) const |
|
Definition at line 591 of file cmt_regexp.cxx. 00591 : cmt_many_node (n) 00592 { 00593 } |
|
Reimplemented from cmt_node. Definition at line 595 of file cmt_regexp.cxx. 00597 { 00598 if ((pos < 0) || (pos > text.size ())) 00599 { 00600 return (cmt_regexp::iterator::null ()); 00601 } 00602 00603 int total = 0; 00604 00605 // 00606 // we are at : x+y 00607 // 00608 00609 int saved_pos = -1; 00610 int saved_total = -1; 00611 bool at_least_one = false; 00612 00613 do 00614 { 00615 const cmt_regexp::iterator itx = _node->match (text, pos); 00616 const cmt_regexp::iterator ity = _follower.match (text, pos); 00617 00618 if ((itx == cmt_regexp::iterator::null ()) && 00619 (ity == cmt_regexp::iterator::null ())) 00620 { 00621 // 00622 // There is neither x nor y. We move back to the last 00623 // succesful match for y. 00624 // 00625 if (saved_pos >= 0) 00626 { 00627 // 00628 // We had once a y. 00629 // 00630 pos = saved_pos; 00631 total = saved_total; 00632 } 00633 else 00634 { 00635 // 00636 // We never had any y ! 00637 // 00638 return (cmt_regexp::iterator::null ()); 00639 } 00640 00641 break; 00642 } 00643 00644 if (itx == cmt_regexp::iterator::null ()) 00645 { 00646 // 00647 // There is a y but no x anymore, fine, we can quit. 00648 // 00649 total += ity._length; 00650 pos += ity._length; 00651 break; 00652 } 00653 00654 if (ity != cmt_regexp::iterator::null ()) 00655 { 00656 // 00657 // We have both x and y. We save the current pos and total, 00658 // and then skip this x. 00659 // 00660 saved_total = total + ity._length; 00661 saved_pos = pos + ity._length; 00662 } 00663 00664 total += itx._length; 00665 pos += itx._length; 00666 00667 at_least_one = true; 00668 } while (true); 00669 00670 if (!at_least_one) return (cmt_regexp::iterator::null ()); 00671 00672 return (cmt_regexp::iterator (pos, total)); 00673 } |