You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by GitBox <gi...@apache.org> on 2019/01/15 19:55:42 UTC
[trafficserver] Diff for: [GitHub] SolidWallOfCode merged pull request
#4798: Regex: Clean up constructors.
diff --git a/include/tscore/Regex.h b/include/tscore/Regex.h
index 6c1572c837..8888ae6009 100644
--- a/include/tscore/Regex.h
+++ b/include/tscore/Regex.h
@@ -31,16 +31,23 @@
#include <pcre.h>
#endif
+/// Match flags for regular expression evaluation.
enum REFlags {
- RE_CASE_INSENSITIVE = 0x0001, // default is case sensitive
- RE_UNANCHORED = 0x0002, // default (for DFA) is to anchor at the first matching position
- RE_ANCHORED = 0x0004, // default (for Regex) is unanchored
+ RE_CASE_INSENSITIVE = 0x0001, ///< Ignore case (default: case sensitive).
+ RE_UNANCHORED = 0x0002, ///< Unanchored (DFA defaults to anchored).
+ RE_ANCHORED = 0x0004, ///< Anchored (Regex defaults to unanchored).
};
+/** Wrapper for PCRE evaluation.
+ *
+ */
class Regex
{
public:
- Regex() : regex(nullptr), regex_extra(nullptr) {}
+ /// Default number of capture groups.
+ static constexpr size_t DEFAULT_GROUP_COUNT = 30;
+
+ Regex() = default;
bool compile(const char *pattern, const unsigned flags = 0);
// It is safe to call exec() concurrently on the same object instance
bool exec(const char *str);
@@ -50,8 +57,8 @@ class Regex
~Regex();
private:
- pcre *regex;
- pcre_extra *regex_extra;
+ pcre *regex = nullptr;
+ pcre_extra *regex_extra = nullptr;
};
typedef struct __pat {
@@ -64,7 +71,7 @@ typedef struct __pat {
class DFA
{
public:
- DFA() : _my_patterns(nullptr) {}
+ DFA() = default;
~DFA();
int compile(const char *pattern, unsigned flags = 0);
@@ -76,5 +83,5 @@ class DFA
private:
dfa_pattern *build(const char *pattern, unsigned flags = 0);
- dfa_pattern *_my_patterns;
+ dfa_pattern *_my_patterns = nullptr;
};
diff --git a/src/tscore/Regex.cc b/src/tscore/Regex.cc
index 1a6cbedff0..79028927e8 100644
--- a/src/tscore/Regex.cc
+++ b/src/tscore/Regex.cc
@@ -109,7 +109,7 @@ Regex::exec(const char *str)
bool
Regex::exec(const char *str, int length)
{
- int ovector[30];
+ int ovector[DEFAULT_GROUP_COUNT];
return exec(str, length, ovector, countof(ovector));
}
With regards,
Apache Git Services