regexp.hh
/* regexp.hh - regular expressions
* Copyright 2004 Bas Wijnen <wijnen@debian.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef SHEVEK_REGEXP_HH
#define SHEVEK_REGEXP_HH
#include <glibmm.h>
#include <sys/types.h>
#include <regex.h>
#include "debug.hh"
namespace shevek
{
class regexp
{
regex_t m_buffer;
bool m_case_sensitive;
regmatch_t *m_match;
unsigned m_size;
std::string m_pattern, m_data;
void l_setup (std::string const &pattern, bool destroy);
public:
regexp (std::string const &pattern = std::string (),
bool case_sensitive = false);
regexp &operator= (std::string const &pattern);
regexp (regexp const &that);
regexp &operator= (regexp const &that);
void case_sensitive (bool value = true);
~regexp ();
bool operator() (std::string const &data);
std::string operator[] (unsigned idx) const;
bool valid (unsigned idx) const;
unsigned size () const;
std::string transform (std::string const &data) const;
std::string const &pattern () const;
};
}
#endif
shevek::regexp::operator()
bool operator()(std::string const &data)
Check whether the pattern matches a string, and fill internal match structures if it does...
shevek::regexp
Use regular expressions.
Definition: regexp.hh:29
shevek::regexp::~regexp
~regexp()
Destructor, this cleans up internal structures.
shevek::regexp::regexp
regexp(std::string const &pattern=std::string(), bool case_sensitive=false)
Create a new object, and optionally fill it with a pattern.
shevek
Definition: args.hh:52
shevek::regexp::operator[]
std::string operator[](unsigned idx) const
Retrieve the value of a subexpression from the last matched string.
shevek::regexp::case_sensitive
void case_sensitive(bool value=true)
Set whether the evaluation should be case sensitive.
shevek::regexp::transform
std::string transform(std::string const &data) const
Transform a string with -codes according to the last matching string.
shevek::regexp::valid
bool valid(unsigned idx) const
Test whether a subexpression was filled by the last matching string.
shevek::regexp::operator=
regexp & operator=(std::string const &pattern)
Set a pattern, removing the previous one.
shevek::regexp::size
unsigned size() const
Get the number of subexpression.
shevek::regexp::pattern
std::string const & pattern() const
Get the current pattern.