util: Correcting code style in regular expression implementation
Change-Id: I7c31c2c8c7a68094da6e73223171b8ac0c886370
Refs: #1403
diff --git a/src/util/regex/regex-component-set-matcher.hpp b/src/util/regex/regex-component-set-matcher.hpp
index e2ff78c..8e0e908 100644
--- a/src/util/regex/regex-component-set-matcher.hpp
+++ b/src/util/regex/regex-component-set-matcher.hpp
@@ -24,20 +24,19 @@
class RegexComponentSetMatcher : public RegexMatcher
{
-
public:
/**
* @brief Create a RegexComponentSetMatcher matcher from expr
* @param expr The standard regular expression to match a component
- * @param exact The flag to provide exact match
- * @param backRefNum The starting back reference number
+ * @param backrefManager Shared pointer to back-reference manager
*/
- RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backRefManager);
+ RegexComponentSetMatcher(const std::string& expr, shared_ptr<RegexBackrefManager> backrefManager);
- virtual ~RegexComponentSetMatcher();
+ virtual
+ ~RegexComponentSetMatcher();
virtual bool
- match(const Name& name, const int& offset, const int& len = 1);
+ match(const Name& name, size_t offset, size_t len = 1);
protected:
/**
@@ -48,57 +47,53 @@
compile();
private:
- int
- extractComponent(int index);
+ size_t
+ extractComponent(size_t index);
void
compileSingleComponent();
void
- compileMultipleComponents(const int start, const int lastIndex);
+ compileMultipleComponents(size_t start, size_t lastIndex);
private:
typedef std::set<shared_ptr<RegexComponentMatcher> > ComponentsSet;
ComponentsSet m_components;
- bool m_include;
+ bool m_isInclusion;
};
inline
RegexComponentSetMatcher::RegexComponentSetMatcher(const std::string& expr,
- shared_ptr<RegexBackrefManager> backRefManager)
- : RegexMatcher(expr, EXPR_COMPONENT_SET, backRefManager),
- m_include(true)
+ shared_ptr<RegexBackrefManager> backrefManager)
+ : RegexMatcher(expr, EXPR_COMPONENT_SET, backrefManager)
+ , m_isInclusion(true)
{
- // _LOG_TRACE ("Enter RegexComponentSetMatcher Constructor");
compile();
- // _LOG_TRACE ("Exit RegexComponentSetMatcher Constructor");
}
inline
RegexComponentSetMatcher::~RegexComponentSetMatcher()
{
- // ComponentsSet::iterator it = m_components.begin();
-
- // for(; it != m_components.end(); it++)
- // delete *it;
}
inline void
RegexComponentSetMatcher::compile()
{
- switch (m_expr[0]){
+ if (m_expr.size() < 2)
+ throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
+
+ switch (m_expr[0]) {
case '<':
return compileSingleComponent();
case '[':
{
- int lastIndex = m_expr.size() - 1;
+ size_t lastIndex = m_expr.size() - 1;
if (']' != m_expr[lastIndex])
- throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
- + " No matched ']' " + m_expr);
+ throw RegexMatcher::Error("Regexp compile error (no matching ']' in " + m_expr + ")");
- if ('^' == m_expr[1]){
- m_include = false;
+ if ('^' == m_expr[1]) {
+ m_isInclusion = false;
compileMultipleComponents(2, lastIndex);
}
else
@@ -106,8 +101,7 @@
break;
}
default:
- throw RegexMatcher::Error(std::string("Error: RegexComponentSetMatcher.compile(): ")
- + "Parsing error in expr " + m_expr);
+ throw RegexMatcher::Error("Regexp compile error (cannot parse " + m_expr + ")");
}
}
@@ -118,8 +112,7 @@
if (m_expr.size() != end)
{
- throw RegexMatcher::Error(
- std::string("Error: RegexComponentSetMatcher.compileSingleComponent: ") + m_expr);
+ throw RegexMatcher::Error("Component expr error " + m_expr);
}
else
{
@@ -131,37 +124,33 @@
}
inline void
-RegexComponentSetMatcher::compileMultipleComponents(const int start, const int lastIndex)
+RegexComponentSetMatcher::compileMultipleComponents(size_t start, size_t lastIndex)
{
- int index = start;
- int tmp_index = start;
+ size_t index = start;
+ size_t tempIndex = start;
- while(index < lastIndex){
+ while (index < lastIndex) {
if ('<' != m_expr[index])
- throw RegexMatcher::Error(
- std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
- "Component expr error " + m_expr);
+ throw RegexMatcher::Error("Component expr error " + m_expr);
- tmp_index = index + 1;
- index = extractComponent(tmp_index);
+ tempIndex = index + 1;
+ index = extractComponent(tempIndex);
shared_ptr<RegexComponentMatcher> component =
- make_shared<RegexComponentMatcher>(m_expr.substr(tmp_index, index - tmp_index - 1),
+ make_shared<RegexComponentMatcher>(m_expr.substr(tempIndex, index - tempIndex - 1),
m_backrefManager);
m_components.insert(component);
}
if (index != lastIndex)
- throw RegexMatcher::Error(
- std::string("Error: RegexComponentSetMatcher.compileMultipleComponents: ") +
- "Not sufficient expr to parse " + m_expr);
+ throw RegexMatcher::Error("Not sufficient expr to parse " + m_expr);
}
inline bool
-RegexComponentSetMatcher::match(const Name& name, const int& offset, const int& len)
+RegexComponentSetMatcher::match(const Name& name, size_t offset, size_t len)
{
- bool matched = false;
+ bool isMatched = false;
/* componentset only matches one component */
if (len != 1)
@@ -175,14 +164,14 @@
{
if ((*it)->match(name, offset, len))
{
- matched = true;
+ isMatched = true;
break;
}
}
m_matchResult.clear();
- if (m_include ? matched : !matched)
+ if (m_isInclusion ? isMatched : !isMatched)
{
m_matchResult.push_back(name.get(offset));
return true;
@@ -191,14 +180,14 @@
return false;
}
-inline int
-RegexComponentSetMatcher::extractComponent(int index)
+inline size_t
+RegexComponentSetMatcher::extractComponent(size_t index)
{
- int lcount = 1;
- int rcount = 0;
+ size_t lcount = 1;
+ size_t rcount = 0;
- while(lcount > rcount){
- switch (m_expr[index]){
+ while (lcount > rcount) {
+ switch (m_expr[index]) {
case '<':
lcount++;
break;