You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafficserver.apache.org by am...@apache.org on 2019/01/15 19:55:44 UTC

[trafficserver] branch master updated: Regex: Clean up constructors.

This is an automated email from the ASF dual-hosted git repository.

amc pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/trafficserver.git


The following commit(s) were added to refs/heads/master by this push:
     new b917405  Regex: Clean up constructors.
b917405 is described below

commit b917405d814ba0ded54b83c6a619ce2c0ce75b3a
Author: Alan M. Carroll <am...@apache.org>
AuthorDate: Mon Jan 14 16:55:37 2019 -0600

    Regex: Clean up constructors.
---
 include/tscore/Regex.h | 23 +++++++++++++++--------
 src/tscore/Regex.cc    |  2 +-
 2 files changed, 16 insertions(+), 9 deletions(-)

diff --git a/include/tscore/Regex.h b/include/tscore/Regex.h
index 6c1572c..8888ae6 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 @@ public:
   ~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 @@ public:
 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 1a6cbed..7902892 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));
 }