- Add CXX11_OVERRIDE to *Regex::Matches and *RegexFactory::Create.
- Fix documentation comment on regex_string.
- Fix various code duplication/layout issues.
class Regex : public classbase
{
protected:
- std::string regex_string; // The raw uncompiled regex string.
+ /** The uncompiled regex string. */
+ std::string regex_string;
// Constructor may as well be protected, as this class is abstract.
- Regex(const std::string& rx) : regex_string(rx)
- {
- }
+ Regex(const std::string& rx) : regex_string(rx) { }
public:
- virtual ~Regex()
- {
- }
+ virtual ~Regex() { }
virtual bool Matches(const std::string& text) = 0;
class RegexFactory : public DataProvider
{
public:
- RegexFactory(Module* Creator, const std::string& Name) : DataProvider(Creator, Name) {}
+ RegexFactory(Module* creator, const std::string& name) : DataProvider(creator, name) { }
virtual Regex* Create(const std::string& expr) = 0;
};
pcre_free(regex);
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
- if (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) > -1)
- {
- // Bang. :D
- return true;
- }
- return false;
+ return (pcre_exec(regex, NULL, text.c_str(), text.length(), 0, 0, NULL, 0) >= 0);
}
};
{
public:
PCREFactory(Module* m) : RegexFactory(m, "regex/pcre") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new PCRERegex(expr);
}
regfree(®buf);
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
- if (regexec(®buf, text.c_str(), 0, NULL, 0) == 0)
- {
- // Bang. :D
- return true;
- }
- return false;
+ return (regexec(®buf, text.c_str(), 0, NULL, 0) == 0);
}
};
public:
bool extended;
PosixFactory(Module* m) : RegexFactory(m, "regex/posix") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new POSIXRegex(expr, extended);
}
}
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
return RE2::FullMatch(text, regexcl);
}
{
public:
RE2Factory(Module* m) : RegexFactory(m, "regex/re2") { }
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new RE2Regex(expr);
}
}
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
return std::regex_search(text, regexcl);
}
public:
std::regex::flag_type regextype;
StdRegexFactory(Module* m) : RegexFactory(m, "regex/stdregex") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new StdRegex(expr, regextype);
}
regfree(®buf);
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
- if (regexec(®buf, text.c_str(), 0, NULL, 0) == 0)
- {
- // Bang. :D
- return true;
- }
- return false;
+ return (regexec(®buf, text.c_str(), 0, NULL, 0) == 0);
}
};
{
public:
TREFactory(Module* m) : RegexFactory(m, "regex/tre") {}
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new TRERegex(expr);
}
{
}
- bool Matches(const std::string& text)
+ bool Matches(const std::string& text) CXX11_OVERRIDE
{
return InspIRCd::Match(text, this->regex_string);
}
class GlobFactory : public RegexFactory
{
public:
- Regex* Create(const std::string& expr)
+ Regex* Create(const std::string& expr) CXX11_OVERRIDE
{
return new GlobRegex(expr);
}