1 /***************************************************************************
3 * Copyright (C) 2006 David Brodsky *
5 * This library is free software; you can redistribute it and/or *
6 * modify it under the terms of the GNU Library General Public *
7 * License as published by the Free Software Foundation and appearing *
8 * in the file LICENSE.LGPL included in the packaging of this file. *
10 * This library is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
13 * Library General Public License for more details. *
15 ***************************************************************************/
17 #ifndef _tairon_util_regexp_regexp_h
18 #define _tairon_util_regexp_regexp_h
22 #include <tairon/core/exceptions.h>
24 using Tairon::Core::String
;
32 /** \brief This class provides pattern matching using POSIX regular
35 * Regular expressions provide a way to to find patterns withing text. It can
36 * be useful in situations like validating, searching, searching and replacing
37 * and string splitting.
42 /** Constructs a regular expression object.
44 * \param pattern Pattern that will be used for matching. See regex(7)
47 RegExp(const char *pattern
);
49 /** Destroys the object and frees all allocated resources.
53 /** Attempts to find a match within a string. Returns position of the
54 * first match, or -1 if there is no match.
56 int match(const String
&s
);
58 /** Returns the text matched by the nth subexpression. The entire match
59 * has index 0 and the parenthesized subexpressions have indices
60 * starting from 1 (excluding non-capturing parentheses).
62 String
matched(int nth
= 0) const;
64 /** Returns length of the nth matched subexpression, or -1 if there is
65 * no such matched subexpression.
67 unsigned int matchedLength(int nth
) const;
69 /** Returns starting position of the nth matched subexpression.
71 unsigned int matchedStart(int nth
) const;
74 /** Size of the match buffer.
78 /** Buffer for matches.
82 /** Pattern buffer storage area.
86 /** String that is searched for a match.
92 /** \brief Exception that is used for RegExp errors.
94 class RegExpException
: public Tairon::Core::Exception
97 /** Standard constructor.
99 RegExpException(const String
&desc
) : Tairon::Core::Exception(desc
) {};
101 /** Default destructor.
103 ~RegExpException() {};
108 }; // namespace Tairon
112 // vim: ai sw=4 ts=4 noet fdm=marker