|  | reflex::LineMatcher Class Reference updated Wed Apr 10 2024 by Robert van Engelen |

- Main Page
- Namespaces
- Classes
- Files

- Class List
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
reflex::LineMatcher Class Reference

Line matcher engine class implements reflex::PatternMatcher pattern matching interface with scan, find, split functors and iterators for matching lines only, use option 'A' to include newline with FIND, option 'N' to also FIND empty lines and option 'W' to only FIND empty lines. More...

`#include <linematcher.h>`

Inheritance diagram for reflex::LineMatcher:
[legend]
Collaboration diagram for reflex::LineMatcher:
[legend]

## Public Member Functions

| LineMatcher (const Input &input=Input(), const char *opt=NULL)
| Construct matcher engine from an input character sequence. More...
| LineMatcher (const LineMatcher &matcher)
| Copy constructor. More...
virtual | ~LineMatcher ()
| Delete matcher. More...
LineMatcher & | operator= (const LineMatcher &matcher)
| Assign a matcher. More...
virtual LineMatcher * | clone ()
| Polymorphic cloning. More...
virtual void | reset (const char *opt=NULL)
| Reset this matcher's state to the initial state and when assigned new input. More...
virtual std::pair< const char *, size_t > | operator[] (size_t) const
| Returns a pair <text(),size() for any n. More...
virtual std::pair< size_t, const char * > | group_id ()
| Returns (0,NULL) More...
virtual std::pair< size_t, const char * > | group_next_id ()
| Returns (0,NULL) More...
Public Member Functions inherited from reflex::AbstractMatcher
| AbstractMatcher (const Input &input, const char *opt)
| Construct a base abstract matcher. More...
| AbstractMatcher (const Input &input, const Option &opt)
| Construct a base abstract matcher. More...
virtual | ~AbstractMatcher ()
| Delete abstract matcher, deletes this matcher's internal buffer. More...
bool | buffer (size_t blk=0)
| Set buffer block size for reading: use 0 (or omit argument) to buffer all input in which case returns true if all the data could be read and false if a read error occurred. More...
void | set_handler (Handler *handler)
| Set event handler functor to invoke when the buffer contents are shifted out, e.g. for logging the data searched. More...
Context | before ()
| Get the buffered context before the matching line. More...
Context | after ()
| Get the buffered context after EOF is reached. More...
void | interactive ()
| Set interactive input with buffer size of 1 to read data bytewise which is very slow. More...
void | flush ()
| Flush the buffer's remaining content. More...
virtual size_t | get (char *s, size_t n)
| Returns more input data directly from the source (method can be overriden, as by reflex::FlexLexer::get(s, n) for example that invokes reflex::FlexLexer::LexerInput(s, n)). More...
virtual bool | wrap ()
| Returns true if wrapping of input after EOF is supported. More...
virtual AbstractMatcher & | input (const Input &input)
| Set the input character sequence for this matcher and reset/restart the matcher. More...
AbstractMatcher & | buffer (char *base, size_t size)
| Set the buffer base containing 0-terminated character data to scan in place (data may be modified), reset/restart the matcher. More...
size_t | matches ()
| Returns nonzero capture index (i.e. true) if the entire input matches this matcher's pattern (and internally caches the true/false result to permit repeat invocations). More...
size_t | accept () const
| Returns a positive integer (true) indicating the capture index of the matched text in the pattern or zero (false) for a mismatch. More...
const char * | begin () const
| Returns pointer to the begin of the matched text (non-0-terminated), a constant-time operation, use with end() or use size() for text end/length. More...
const char * | end () const
| Returns pointer to the exclusive end of the matched text, a constant-time operation. More...
const char * | text ()
| Returns 0-terminated string of the text matched, does not include matched \0s, this is a constant-time operation. More...
std::string | str () const
| Returns the text matched as a string, a copy of text(), may include matched \0s. More...
std::wstring | wstr () const
| Returns the match as a wide string, converted from UTF-8 text(), may include matched \0s. More...
size_t | size () const
| Returns the length of the matched text in number of bytes, including matched \0s, a constant-time operation. More...
size_t | wsize () const
| Returns the length of the matched text in number of wide characters. More...
int | chr () const
| Returns the first 8-bit character of the text matched. More...
int | wchr () const
| Returns the first wide character of the text matched. More...
void | lineno (size_t n)
| Set or change the starting line number of the last match. More...
size_t | lineno ()
| Updates and returns the starting line number of the match in the input character sequence. More...
size_t | lines ()
| Returns the number of lines that the match spans. More...
size_t | lineno_end ()
| Returns the inclusive ending line number of the match in the input character sequence. More...
void | columno (size_t n)
| Set or change the starting column number of the last match. More...
size_t | columno ()
| Updates and returns the starting column number of the matched text, taking tab spacing into account and counting wide characters as one character each. More...
size_t | columns ()
| Returns the number of columns of the matched text, taking tab spacing into account and counting wide characters as one character each. More...
size_t | columno_end ()
| Returns the inclusive ending column number of the matched text on the ending matching line, taking tab spacing into account and counting wide characters as one character each. More...
std::pair< size_t, std::string > | pair () const
| Returns std::pair<size_t,std::string>(accept(), str()), useful for tokenizing input into containers of pairs. More...
std::pair< size_t, std::wstring > | wpair () const
| Returns std::pair<size_t,std::wstring>(accept(), wstr()), useful for tokenizing input into containers of pairs. More...
size_t | first () const
| Returns the position of the first character of the match in the input character sequence, a constant-time operation. More...
size_t | last () const
| Returns the exclusive position of the last character of the match in the input character sequence, a constant-time operation. More...
bool | at_bob () const
| Returns true if this matcher is at the start of a buffer to read an input character sequence. Use reset() to restart reading new input. More...
void | set_bob (bool bob)
| Set/reset the begin of a buffer state. More...
bool | at_end ()
| Returns true if this matcher has no more input to read from the input character sequence. More...
bool | hit_end () const
| Returns true if this matcher hit the end of the input character sequence. More...
void | set_end (bool eof)
| Set and force the end of input state. More...
bool | at_bol () const
| Returns true if this matcher reached the begin of a new line. More...
void | set_bol (bool bol)
| Set/reset the begin of a new line state. More...
bool | at_bow ()
| Returns true if this matcher matched text that begins a word. More...
bool | at_eow ()
| Returns true if this matcher matched text that ends a word. More...
int | input ()
| Returns the next 8-bit character (unsigned char 0..255 or EOF) from the input character sequence, while preserving the current text() match (but pointer returned by text() may change; warning: does not preserve the yytext string pointer when options –flex and –bison are used). More...
int | winput ()
| Returns the next wide character (unsigned 0..U+10FFFF or EOF) from the input character sequence, while preserving the current text() match (but pointer returned by text() may change; warning: does not preserve the yytext string pointer when options –flex and –bison are used). More...
void | unput (char c)
| Put back one character (8-bit) on the input character sequence for matching, DANGER: invalidates the previous text() pointer and match info, unput is not honored when matching in-place using buffer(base, size) and nothing has been read yet. More...
void | wunput (int c)
| Put back one (wide) character on the input character sequence for matching, DANGER: invalidates the previous text() pointer and match info, unput is not honored when matching in-place using buffer(base, size) and nothing has been read yet. More...
int | peek ()
| Peek at the next character available for reading from the current input source. More...
const char * | bol ()
| Returns pointer to the begin of the line in the buffer containing the matched text. More...
const char * | eol (bool inclusive=false)
| Returns pointer to the end of the line (last char + 1) in the buffer containing the matched text, DANGER: invalidates previous bol() and text() pointers, use eol() before bol(), text(), begin(), and end() when those are used. More...
size_t | avail ()
| Returns the number of bytes in the buffer available to search from the current begin()/text() position. More...
size_t | border ()
| Returns the byte offset of the match from the start of the line. More...
const char * | span ()
| Enlarge the match to span the entire line of input (excluding ), return text(). More...
std::string | line ()
| Returns the line of input (excluding ) as a string containing the matched text as a substring. More...
std::wstring | wline ()
| Returns the line of input (excluding ) as a wide string containing the matched text as a substring. More...
bool | skip (char c)
| Skip input until the specified ASCII character is consumed and return true, or EOF is reached and return false. More...
bool | skip (wchar_t c)
| Skip input until the specified Unicode character is consumed and return true, or EOF is reached and return false. More...
bool | skip (const char *s)
| Skip input until the specified literal UTF-8 string is consumed and return true, or EOF is reached and return false. More...
const char * | rest ()
| Fetch the rest of the input as text, useful for searching/splitting up to n times after which the rest is needed. More...
void | more ()
| Append the next match to the currently matched text returned by AbstractMatcher::text, when the next match found is adjacent to the current match. More...
void | less (size_t n)
| Truncate the AbstractMatcher::text length of the match to n characters in length and reposition for next match. More...
| operator size_t () const
| Cast this matcher to positive integer indicating the nonzero capture index of the matched text in the pattern, same as AbstractMatcher::accept. More...
| operator std::string () const
| Cast this matcher to a std::string of the text matched by this matcher. More...
| operator std::wstring () const
| Cast this matcher to a std::wstring of the text matched by this matcher. More...
| operator std::pair< size_t, std::string > () const
| Cast the match to std::pair<size_t,std::wstring>(accept(), wstr()), useful for tokenization into containers. More...
bool | operator== (const char *rhs) const
| Returns true if matched text is equal to a string, useful for std::algorithm. More...
bool | operator== (const std::string &rhs) const
| Returns true if matched text is equalt to a string, useful for std::algorithm. More...
bool | operator== (size_t rhs) const
| Returns true if capture index is equal to a given size_t value, useful for std::algorithm. More...
bool | operator== (int rhs) const
| Returns true if capture index is equal to a given int value, useful for std::algorithm. More...
bool | operator!= (const char *rhs) const
| Returns true if matched text is not equal to a string, useful for std::algorithm. More...
bool | operator!= (const std::string &rhs) const
| Returns true if matched text is not equal to a string, useful for std::algorithm. More...
bool | operator!= (size_t rhs) const
| Returns true if capture index is not equal to a given size_t value, useful for std::algorithm. More...
bool | operator!= (int rhs) const
| Returns true if capture index is not equal to a given int value, useful for std::algorithm. More...
void | tabs (char n)
| Set tab size 1, 2, 4, or 8. More...
char | tabs ()
| Returns current tab size 1, 2, 4, or 8. More...

## Protected Member Functions

virtual size_t | match (Method method)
| The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH. More...
Protected Member Functions inherited from reflex::AbstractMatcher
virtual void | init (const char *opt=NULL)
| Initialize the base abstract matcher at construction. More...
bool | grow (size_t need=Const::BLOCK)
| Shift or expand the internal buffer when it is too small to accommodate more input, where the buffer size is doubled when needed, change cur_, pos_, end_, max_, ind_, buf_, bol_, lpb_, and txt_. More...
int | get ()
| Returns the next character read from the current input source. More...
void | reset_text ()
| Reset the matched text by removing the terminating \0, which is needed to search for a new match. More...
void | set_current (size_t loc)
| Set the current position in the buffer for the next match. More...
void | set_current_and_peek_more (size_t loc)
| Set the current match position in the buffer and peek for more text, allows large buffer shifts that aren't pinned to txt_. More...
int | get_more ()
| Get the next character and grow the buffer to make more room if necessary. More...
int | peek_more ()
| Peek at the next character and grow the buffer to make more room if necessary. More...

## Protected Attributes

bool | inc_
| true if next find() should skip over More...
Protected Attributes inherited from reflex::AbstractMatcher
Option | opt_
| options for matcher engines More...
char * | buf_
| input character sequence buffer More...
char * | txt_
| points to the matched text in buffer AbstractMatcher::buf_ More...
size_t | len_
| size of the matched text More...
size_t | cap_
| nonzero capture index of an accepted match or zero More...
size_t | cur_
| next position in AbstractMatcher::buf_ to assign to AbstractMatcher::txt_ More...
size_t | pos_
| position in AbstractMatcher::buf_ after AbstractMatcher::txt_ More...
size_t | end_
| ending position of the input buffered in AbstractMatcher::buf_ More...
size_t | max_
| total buffer size and max position + 1 to fill More...
size_t | ind_
| current indent position More...
size_t | blk_
| block size for block-based input reading, as set by AbstractMatcher::buffer More...
int | got_
| last unsigned character we looked at (to determine anchors and boundaries) More...
int | chr_
| the character located at AbstractMatcher::txt_[AbstractMatcher::len_] More...
const char * | bol_
| begin of line pointer in buffer More...
Handler * | evh_
| event handler functor to invoke when buffer contents are shifted out More...
const char * | lpb_
| line pointer in buffer, updated when counting line numbers with lineno() More...
size_t | lno_
| line number count (cached) More...
const char * | cpb_
| column pointer in buffer, updated when counting column numbers with columno() More...
size_t | cno_
| column number count (cached) More...
size_t | num_
| character count of the input till bol_ More...
bool | own_
| true if AbstractMatcher::buf_ was allocated and should be deleted More...
bool | eof_
| input has reached EOF More...
bool | mat_
| true if AbstractMatcher::matches() was successful More...

## Additional Inherited Members

Public Types inherited from reflex::AbstractMatcher
typedef AbstractMatcher::Iterator< AbstractMatcher > | iterator
| std::input_iterator for scanning, searching, and splitting input character sequences More...
typedef AbstractMatcher::Iterator< const AbstractMatcher > | const_iterator
Public Attributes inherited from reflex::AbstractMatcher
Operation | scan
| functor to scan input (to tokenize input) More...
Operation | find
| functor to search input More...
Operation | split
| functor to split input More...
Input | in
| input character sequence being matched by this matcher More...
Protected Types inherited from reflex::AbstractMatcher
typedef int | Method
| a method is one of Const::SCAN, Const::FIND, Const::SPLIT, Const::MATCH More...

## Detailed Description

Line matcher engine class implements reflex::PatternMatcher pattern matching interface with scan, find, split functors and iterators for matching lines only, use option 'A' to include newline with FIND, option 'N' to also FIND empty lines and option 'W' to only FIND empty lines.

## Constructor & Destructor Documentation

reflex::LineMatcher::LineMatcher | ( | const Input & | input = `Input()`,
|  | const char * | opt = `NULL`
| ) |  |

inline

Construct matcher engine from an input character sequence.

Parameters

  input | input character sequence for this matcher
  opt | option string of the form `(A|N|T(=[[:digit:]])?|;)*`

reflex::LineMatcher::LineMatcher | ( | const LineMatcher & | matcher | ) |

inline

Copy constructor.

Parameters

  matcher | matcher to copy

virtual reflex::LineMatcher::~LineMatcher | ( |  | ) |

inline virtual

Delete matcher.

## Member Function Documentation

virtual LineMatcher* reflex::LineMatcher::clone | ( |  | ) |

inline virtual

Polymorphic cloning.

Implements reflex::AbstractMatcher.

virtual std::pair<size_t,const char*> reflex::LineMatcher::group_id | ( |  | ) |

inline virtual

Returns (0,NULL)

Returns
  a pair of size_t and string

Implements reflex::AbstractMatcher.

virtual std::pair<size_t,const char*> reflex::LineMatcher::group_next_id | ( |  | ) |

inline virtual

Returns (0,NULL)

Returns
  a pair of size_t and string

Implements reflex::AbstractMatcher.

virtual size_t reflex::LineMatcher::match | ( | Method | method | ) |

inline protected virtual

The match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH.

Returns
  nonzero when input matched a line

Parameters

  method | match method Const::SCAN, Const::FIND, Const::SPLIT, or Const::MATCH

Implements reflex::AbstractMatcher.

LineMatcher& reflex::LineMatcher::operator= | ( | const LineMatcher & | matcher | ) |

inline

Assign a matcher.

Parameters

  matcher | matcher to copy

virtual std::pair<const char*,size_t> reflex::LineMatcher::operator[] | ( | size_t |  | ) | const

inline virtual

Returns a pair <text(),size() for any n.

Returns
  pair.

Implements reflex::AbstractMatcher.

virtual void reflex::LineMatcher::reset | ( | const char * | opt = `NULL` | ) |

inline virtual

Reset this matcher's state to the initial state and when assigned new input.

Reimplemented from reflex::AbstractMatcher.

## Member Data Documentation

bool reflex::LineMatcher::inc_

protected

true if next find() should skip over

The documentation for this class was generated from the following file:

- linematcher.h