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 //
10 #include <anna/core/util/RegularExpression.hpp>
12 #include <anna/core/util/Tokenizer.hpp>
13 #include <anna/core/functions.hpp>
16 //using namespace anna;
20 void anna::RegularExpression::freeRegex() throw() {
27 void anna::RegularExpression::compile() throw(anna::RuntimeException) {
28 if(a_compiled) return;
32 if((ret = regcomp(&a_preg, a_pattern.c_str(), REG_EXTENDED)) != 0) {
34 std::string msg("anna::RegularExpression::setPattern | ");
35 msg += " | Pattern: ";
39 if(regerror(ret, &a_preg, err, sizeof(err)))
42 msg += "Invalid pattern provided";
44 throw anna::RuntimeException(msg, ANNA_FILE_LOCATION);
52 //------------------------------------------------------------------------------
53 //---------------------------------------------- RegularExpression::setPattern()
54 //------------------------------------------------------------------------------
55 void anna::RegularExpression::setPattern(const std::string & pattern) throw() {
56 if(pattern == a_pattern) return;
63 //------------------------------------------------------------------------------
64 //-------------------------------------------------- RegularExpression::isLike()
65 //------------------------------------------------------------------------------
66 bool anna::RegularExpression::isLike(const std::string & value) throw() {
68 const bool result = (regexec(&a_preg, value.c_str(), 0, NULL, 0) == 0) ? true : false;
73 //------------------------------------------------------------------------------
74 //------------------------------------------------ RegularExpression::operator==
75 //------------------------------------------------------------------------------
76 bool anna::RegularExpression::operator == (const RegularExpression & re) const {
77 return (getPattern() == re.getPattern());
81 //------------------------------------------------------------------------------
82 //------------------------------------------------- RegularExpression::operator<
83 //------------------------------------------------------------------------------
84 bool anna::RegularExpression::operator < (const RegularExpression & re) const {
85 return (getPattern() < re.getPattern());