From e53596b7a92d400b88faefd4bb58a792dceb8297 Mon Sep 17 00:00:00 2001 From: Ben Boeckel <ben.boeckel@kitware.com> Date: Sat, 8 Feb 2014 03:37:28 -0500 Subject: [PATCH] RegularExpression: Add string overloads It's weird that find had one (non-inline) overload. Make overloads for the ctor and .compile() as well so that other code can drop unnecessary .c_str() calls. Change-Id: If0da9811728892bdfd1340f51ec9b33524776958 --- RegularExpression.cxx | 7 ------- RegularExpression.hxx.in | 43 ++++++++++++++++++++++++++++++++++++++-- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/RegularExpression.cxx b/RegularExpression.cxx index c829787..598e7ca 100644 --- a/RegularExpression.cxx +++ b/RegularExpression.cxx @@ -882,13 +882,6 @@ void regdump (); static char* regprop (); #endif -bool RegularExpression::find (kwsys_stl::string const& s) -{ - return find(s.c_str()); -} - - - // find -- Matches the regular expression to the given string. // Returns true if found, and sets start and end indexes accordingly. diff --git a/RegularExpression.hxx.in b/RegularExpression.hxx.in index 62e9cad..502fbe2 100644 --- a/RegularExpression.hxx.in +++ b/RegularExpression.hxx.in @@ -198,12 +198,17 @@ public: * Instantiate RegularExpression with compiled char*. */ inline RegularExpression (char const*); - + /** * Instantiate RegularExpression as a copy of another regular expression. */ RegularExpression (RegularExpression const&); + /** + * Instantiate RegularExpression with compiled string. + */ + inline RegularExpression (kwsys_stl::string const&); + /** * Destructor. */ @@ -215,6 +220,12 @@ public: */ bool compile (char const*); + /** + * Compile a regular expression into internal code + * for later pattern matching. + */ + inline bool compile (kwsys_stl::string const&); + /** * Matches the regular expression to the given string. * Returns true if found, and sets start and end indexes accordingly. @@ -225,7 +236,7 @@ public: * Matches the regular expression to the given std string. * Returns true if found, and sets start and end indexes accordingly. */ - bool find (kwsys_stl::string const&); + inline bool find (kwsys_stl::string const&); /** * Index to start of first find. @@ -312,6 +323,16 @@ inline RegularExpression::RegularExpression (const char* s) } } +/** + * Creates a regular expression from string s, and + * compiles s. + */ +inline RegularExpression::RegularExpression (const kwsys_stl::string& s) +{ + this->program = 0; + this->compile(s); +} + /** * Destroys and frees space allocated for the regular expression. */ @@ -322,6 +343,24 @@ inline RegularExpression::~RegularExpression () //#endif } +/** + * Compile a regular expression into internal code + * for later pattern matching. + */ +inline bool RegularExpression::compile (kwsys_stl::string const& s) +{ + return this->compile(s.c_str()); +} + +/** + * Matches the regular expression to the given std string. + * Returns true if found, and sets start and end indexes accordingly. + */ +inline bool RegularExpression::find (kwsys_stl::string const& s) +{ + return this->find(s.c_str()); +} + /** * Set the start position for the regular expression. */ -- GitLab