OWLNext    7.0
Borland's Object Windows Library for the modern age
Loading...
Searching...
No Matches
owl::TRegexp Class Reference

This class represents regular expressions. More...

#include <owl/private/regexp.h>

Public Types

enum  StatVal { OK =0 , ILLEGAL , NOMEMORY , TOOLONG }
 StatVal enumerates the status conditions returned by TRegexp::status. More...
 

Public Member Functions

 TRegexp (const tchar *cp)
 
 TRegexp (const TRegexp &r)
 
 ~TRegexp ()
 
TRegexpoperator= (const TRegexp &r)
 
TRegexpoperator= (const tchar *cp)
 
size_t find (const tstring &s, size_t *len, size_t start=0) const
 
StatVal status () noexcept
 

Detailed Description

This class represents regular expressions.

TRegexp is a support class used by the string class for string searches. Regular expressions use these special characters:

. [ ] - ^ * ? + $

General Rules

Characters other than the special characters match themselves. For example "yardbird" matches "yardbird". A backslash (\) followed by a special character, matches the special character itself. For example "Pardon\\?" matches "Pardon?". The following escape codes can be used to match control characters:

One-Character Regular Expressions

  • The . special character matches any single character except a newline character. For example ".ive" would match "jive" or "five".
  • The [ and ] special characters are used to denote one-character regular expressions that will match any of the characters within the brackets. For example, "[aeiou]" would match either "a", "e", "i", "o", or "u".
  • The - special character is used within the [ ] special characters to denote a range of characters to match. For example, "[ a-z ]" would match on any lowercase alphabetic character between a and z.
  • The ^ special character is used to specify search for any character but those specified. For example, "[ ^g-v ]" would match on any lowercase alphabetic character NOT between g and v.

    Multiple-Character Regular Expressions

  • The * special character following a one-character regular expression matches zero or more occurrences of that regular expression. For example, "[ a-z ]*" matches zero or more occurrences of lowercase alphabetic characters.
  • The + special character following a one-character regular expression matches one or more occurrences of that regular expression. For example, "[ 0-9 ]+" matches one or more occurrences of lowercase alphabetic characters.
  • The ? special character specifies that the following character is optional. For example "xy?z" matches on "xy" or "xyz".

Regular expressions can be concatentated. For example, "[ A-Z ][ a-z ]*" matches capitalized words.

Matching at the Beginning and End of a Line If the ^ special character is at the beginning of a regular expression, then a match occurs only if the string is at the beginning of a line. For example, "^[ A-Z ][ a-z ]*" matches capitalized words at the beginning of a line. If the $ special character is at the end of a regular expression, the then a match occurs only if the string is at the end of a line. For example, "[ A-Z ][ a-z ]*$" matches capitalized words at the end of a line.

Definition at line 94 of file regexp.h.

Member Enumeration Documentation

◆ StatVal

StatVal enumerates the status conditions returned by TRegexp::status.

Enumerator
OK 

Means the given regular expression is legal.

ILLEGAL 

Means the pattern was illegal.

NOMEMORY 
TOOLONG 

Means the pattern exceeded maximum length (128)

Definition at line 97 of file regexp.h.

Constructor & Destructor Documentation

◆ TRegexp() [1/2]

owl::TRegexp::TRegexp ( const tchar * cp)

Definition at line 29 of file regexp.cpp.

◆ TRegexp() [2/2]

owl::TRegexp::TRegexp ( const TRegexp & r)

Definition at line 34 of file regexp.cpp.

◆ ~TRegexp()

owl::TRegexp::~TRegexp ( )

Definition at line 39 of file regexp.cpp.

Member Function Documentation

◆ find()

size_t owl::TRegexp::find ( const tstring & s,
size_t * len,
size_t start = 0 ) const

Definition at line 86 of file regexp.cpp.

References owl::matchs(), OK, and PRECONDITION.

◆ operator=() [1/2]

TRegexp & owl::TRegexp::operator= ( const tchar * cp)

Definition at line 57 of file regexp.cpp.

◆ operator=() [2/2]

TRegexp & owl::TRegexp::operator= ( const TRegexp & r)

Definition at line 64 of file regexp.cpp.

◆ status()

TRegexp::StatVal owl::TRegexp::status ( )
noexcept

Definition at line 74 of file regexp.cpp.

References OK.


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