Main Page | Class List | Directories | File List | Class Members

basic_regexp_parser Class Template Reference

#include <regexp_parser.h>

List of all members.

Public Member Functions

 basic_regexp_parser (std::basic_string< E > regular_expression)
bool is_pattern_valid ()
 Returns 'true', if regexp pattern passed into constructor is valid.
virtual unsigned long parse (const E *buf, const unsigned long buf_length)
 Uses regexp pattern to find match in the input buffer.
virtual std::basic_istream<
E > & 
parse (std::basic_istream< E > &is)
 Uses regexp pattern to find match in the input stream.
unsigned long recognized_position ()
 Returns the match position in the input.
unsigned long recognized_size ()
 Returns the match size in the input.
void assign_matches (extended_regular_expression::matches &m)
 Assigns matches of all subexpressions.
virtual std::basic_ostream<
E > & 
format (std::basic_ostream< E > &os)
 Formats the preceding characters together with match string back into output stream.
 operator std::basic_string ()
 Returns the match as a string together with characters before match position.

Protected Member Functions

void prepare_for_parsing ()

Protected Attributes

std::basic_string< E > m_regular_expression
basic_non_terminal< E, extended_regular_expression::ere<
E > > 
m_regexp


Detailed Description

template<typename E>
class base_parsers::basic_regexp_parser< E >

The class for parsing strings using regular expressions. The implementation accomplishes The Open Group specification Issue 6, IEEE Std 1003.1, 2004 Edition, Copyright 2001-2004 The IEEE and The Open Group. The parser was also extended to return matches of the regexp and to address all subexpressions matches. With use of matches it is possible to manipulate the input string


Member Function Documentation

void assign_matches extended_regular_expression::matches &  m  )  [inline]
 

Assigns matches of all subexpressions.

The method retrieves all subexpressions data (position and size in original input buffer). Each subexpression is addressed by a key. In the match key, the number specifies the subexpression position, by '.' are separated levels, i.e. "a" is addresses by 1, "(a)" by 1.1, "((a))" by 1.1.1 etc. By number is specified the subexpression position on the level. Suppose we have pattern "a(a(b){1,3})" and input "aaabbbb". Now we are interested in subexression 1.1.2 = second b

                        regexp_parser rxp("a(a(b){1,3})");
                        rxp.parse( "aaabbbb", 7 );
        
                        matches m;
                        rxp.assign_matches(m);
                        match subexpr = m.get("1.1.2");
                        if( subexpr.this->is_valid() )
                        {
                                ulong pos = subexpr.get_pos();  // == 4
                                ulong size = subexpr.get_size();// == 1 
                                // do some work
                        }

virtual std::basic_istream<E>& parse std::basic_istream< E > &  is  )  [inline, virtual]
 

Uses regexp pattern to find match in the input stream.

The constructor parameter is used as regexp pattern during parsing

Parameters:
is input stream
Returns:
input stream with 'get' position shifted by parsed size

virtual unsigned long parse const E *  buf,
const unsigned long  buf_length
[inline, virtual]
 

Uses regexp pattern to find match in the input buffer.

The constructor parameter is used as regexp pattern during parsing

Parameters:
buf input buffer
buf_length input buffer length
Returns:
parsed size


The documentation for this class was generated from the following file:
Generated on Tue Nov 14 21:19:55 2006 for regexp_parser.kdevelop by  doxygen 1.4.4