Main Page ? Class Hierarchy ? Compound List ? File List ? Compound Members ? File Members ?

cmt_and_node Class Reference

Inheritance diagram for cmt_and_node:

[legend]
Collaboration diagram for cmt_and_node:

[legend]
List of all members.

Public Methods

? cmt_and_node ()
? cmt_and_node (cmt_regexp_node_set *father)
const cmt_regexp::iterator? match (const cmt_string &text, int pos) const
void? reduce ()
void? fill (cmt_and_node &other, int start_index)

Constructor & Destructor Documentation

cmt_and_node::cmt_and_node (? ? )?
?

Definition at line 784 of file cmt_regexp.cxx.

00784                             : cmt_regexp_node_set ()
00785 {
00786 }

cmt_and_node::cmt_and_node (? cmt_regexp_node_set *? ? father )?
?

Definition at line 788 of file cmt_regexp.cxx.

00788                                                        : cmt_regexp_node_set (father)
00789 {
00790 }

Member Function Documentation

void cmt_and_node::fill (? cmt_and_node &? ? other,
int? ? start_index
)?
?

Definition at line 893 of file cmt_regexp.cxx.

References cmt_regexp_node_set::_nodes, cmt_regexp_node_set::nodes(), and cmt_regexp_node_set::push().

Referenced by cmt_many_node::install().

00894 {
00895   if ((start_index < 0) || (start_index > other.nodes ())) return;
00896 
00897   for (int i = start_index; i < other.nodes (); i++)
00898     {
00899       cmt_regexp_node* n = other._nodes[i];
00900       push (n);
00901     }
00902 }

const cmt_regexp::iterator cmt_and_node::match (? const cmt_string &? ? text,
int? ? pos
)? const [virtual]
?

Reimplemented from cmt_regexp_node.

Definition at line 792 of file cmt_regexp.cxx.

References cmt_regexp::iterator::_length, cmt_regexp_node_set::_nodes, cmt_regexp_node::match(), cmt_regexp::iterator::null(), cmt_vector< cmt_regexp_node * >::size(), and cmt_string::size().

Referenced by cmt_one_more::match(), and cmt_zero_more::match().

00794 {
00795   if ((pos < 0) || (pos > text.size ())) 
00796     {
00797       return (cmt_regexp::iterator::null ());
00798     }
00799 
00800   if (_nodes.size () == 0) return (cmt_regexp::iterator (pos, 0));
00801 
00802   int i;
00803   int total = 0;
00804   int p = pos;
00805   
00806   for (i = 0; i < _nodes.size (); i++)
00807     {
00808       cmt_regexp_node* n = _nodes[i];
00809       
00810       const cmt_regexp::iterator it = n->match (text, p);
00811       
00812       if (it == cmt_regexp::iterator::null ()) return (it);
00813       
00814       total += it._length;
00815       p += it._length;
00816     }
00817 
00818     // All nodes match
00819   
00820   return (cmt_regexp::iterator (pos, total));
00821 }

void cmt_and_node::reduce (? ? )? [virtual]
?

Reimplemented from cmt_regexp_node_set.

Definition at line 823 of file cmt_regexp.cxx.

References cmt_regexp_node_set::_nodes, cmt_many_node::install(), cmt_regexp_node::is_char(), cmt_regexp_node::is_many_node(), cmt_vector< T >::push_back(), cmt_many_node::reduce(), cmt_string::size(), and cmt_vector< cmt_regexp_node * >::size().

Referenced by cmt_many_node::reduce().

00824 {
00825   if (_nodes.size () < 2) return;
00826   
00827   char c = ' ';
00828   cmt_string s = "";
00829   cmt_vector new_nodes;
00830 
00831   //
00832   // We loop once too much in order to finish the possibly accumulated
00833   // string at the end.
00834   //
00835   for (int i = 0; i <= _nodes.size (); i++)
00836     {
00837       cmt_regexp_node* n = 0;
00838 
00839       if (i < _nodes.size ()) n = _nodes[i];
00840 
00841       if ((i >= _nodes.size ()) || (!n->is_char ()))
00842         {
00843           if (s.size () == 1)
00844             {
00845               //
00846               // Too bad there was only one char node to consider
00847               // let's put it back as a char node !
00848               //
00849               new_nodes.push_back (new cmt_char_node (c));
00850               s = "";
00851             }
00852           else if (s.size () > 1)
00853             {
00854               //
00855               // We have real reduction here sonce there was several
00856               // consecutive char nodes.
00857               //
00858               new_nodes.push_back (new cmt_string_node (s));
00859               s = "";
00860             }
00861 
00862           if (i >= _nodes.size ()) break;
00863         }
00864 
00865       if (n->is_char ())
00866         {
00867           //
00868           // We are now trying to compact those char nodes.
00869           //
00870           cmt_char_node& cn = *((cmt_char_node*) n);
00871           c = (char) cn;
00872           s += c;
00873           delete n;
00874           _nodes[i] = 0;
00875         }
00876       else if (n->is_many_node ())
00877         {
00878           cmt_many_node& mn = *((cmt_many_node*) n);
00879           mn.install (*this, i + 1);
00880           mn.reduce ();
00881           new_nodes.push_back (n);
00882           break;
00883         }
00884       else
00885         {
00886           new_nodes.push_back (n);
00887         }
00888     }
00889   
00890   _nodes = new_nodes;
00891 }

The documentation for this class was generated from the following file:
Generated on Thu Jul 1 15:26:31 2004 for CMT by 1.2.18