NAME

OTC_Regex - Class for performing regular expression matches.

SYNOPSIS


#include <OTC/text/regex.hh>

class OTC_Regex : public OTC_Pattern
{
  public:
    static os_typespec* get_os_typespec();
    ~OTC_Regex();
    OTC_Regex(char const* thePattern);
    OTC_Boolean isValid() const;
    OTC_Boolean match(char const* theString);
    u_int start() const;
    u_int start(u_int theIndex) const;
    u_int length() const;
    u_int length(u_int theIndex) const;
    inline OTC_Range range() const;
    OTC_Range range(u_int theIndex) const;
    inline void modw(char const* theString);
    inline char const* error() const;
    static OTC_Regex& whiteSpace();
    static OTC_Regex& optWhiteSpace();
    static OTC_Regex& nonWhiteSpace();
    static OTC_Regex& alphabetic();
    static OTC_Regex& lowerCase();
    static OTC_Regex& upperCase();
    static OTC_Regex& alphaNumeric();
    static OTC_Regex& identifier();
    static OTC_Regex& matchingQuotes();
  protected:
    inline void compile();
    OTC_Boolean re_comp(char const* pat);
    int re_exec(char const* lp);
    void re_modw(char const* s);
    int re_subs(char const* src, char* dst);
    virtual void re_fail(char const* msg, char op);
};

CLASS TYPE

Concrete

DESCRIPTION

This class can be used to determine if some string matches a particular regular expression. In addition, information can be obtained about the match, so that string substitutions can be undertaken. The pattern style is like that for ex(1).

INITIALISATION

OTC_Regex(char const* thePattern);

PATTERN COMPILATION

inline void compile();

ERRORS

OTC_Boolean isValid() const;

PATTERN MATCHING

OTC_Boolean match(char const* theString);
The following functions return information about the area of a string which a pattern matched with. A value of 0 for theIndex indicates matches with the complete pattern. A value greater than zero indicates matches with subpatterns as designated by the \\(\\) notation. All functions return 0 if no match has occurred.
u_int start() const;
u_int start(u_int theIndex) const;
u_int length() const;
u_int length(u_int theIndex) const;
inline OTC_Range range() const;
OTC_Range range(u_int theIndex) const;

CUSTOMISATION

inline void modw(char const* theString);

BUILTIN REGULAR EXPRESSIONS

Some commonly used regular expressions are defined as constant character strings. These are:
static OTC_Regex& whiteSpace();
static OTC_Regex& optWhiteSpace();
static OTC_Regex& nonWhiteSpace();
static OTC_Regex& alphabetic();
static OTC_Regex& lowerCase();
static OTC_Regex& upperCase();
static OTC_Regex& alphaNumeric();
static OTC_Regex& identifier();
static OTC_Regex& matchingQuotes();

REGULAR EXPRESSIONS

Regular expressions can be of the following forms: [1] char [2] . [3] \\ [4] [set] [5] * [6] + [7] [8] [9] \\<\\> [10] [11] ^ $ [12] \\b \\n \\f \\r \\t

NOTES

This uses the regex routines in v07i021 of volume 7 of comp.sources.misc.

SEE ALSO

ex(1), OTC_Pattern

LIBRARY

OTC

AUTHOR(S)

Graham Dumpleton

COPYRIGHT

Copyright 1991 1992 OTC LIMITED
Copyright 1994 DUMPLETON SOFTWARE CONSULTING PTY LIMITED