1 // ANNA - Anna is Not Nothingness Anymore //
3 // (c) Copyright 2005-2015 Eduardo Ramos Testillano & Francisco Ruiz Rayo //
5 // See project site at http://redmine.teslayout.com/projects/anna-suite //
6 // See accompanying file LICENSE or copy at http://www.teslayout.com/projects/public/anna.LICENSE //
9 #ifndef anna_core_util_RegularExpression_hpp
10 #define anna_core_util_RegularExpression_hpp
19 #include <anna/core/RuntimeException.hpp>
25 * Class helper to manage regular expressions with efficiency (first compile & keep pattern, then reuse match procedure with different values)
27 class RegularExpression {
29 std::string a_pattern;
35 void freeRegex() throw();
36 void compile() throw(anna::RuntimeException);
40 RegularExpression(const std::string & pattern = "") : a_pattern(pattern), a_compiled(false) {};
41 ~RegularExpression() { freeRegex(); }
47 * Set the pattern for regular expression
49 * @param pattern Pattern
51 void setPattern(const std::string & pattern) throw();
57 * Get the current pattern for the regular expression
61 const std::string & getPattern(void) const throw() { return a_pattern; }
66 * Check if value fulfill regular expression
68 * @return Boolean about if value provided match regular expression
70 bool isLike(const std::string & value) throw();
75 bool match(const std::string & value) throw() { return isLike(value); }
80 * @param re Instance from RegularExpression class
82 * @return Returns re == this comparison based on private 'pattern' member
84 bool operator == (const RegularExpression & re) const;
89 * @param re Instance from RegularExpression class
91 * @return Returns re < this comparison based on private 'pattern' member
93 bool operator < (const RegularExpression & re) const;