From b7928899936522b3d03aef1cca566030510f6a01 Mon Sep 17 00:00:00 2001 From: Robert Ogden Date: Wed, 26 Jul 2023 11:24:47 -0700 Subject: [PATCH] use re2 instead of std regex --- .../mediapipe/src/mediapipe/framework/deps/re2.h | 44 ++-------------------- 1 file changed, 3 insertions(+), 41 deletions(-) diff --git a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h index b1b5532eb0380..4079d9c0d1916 100644 --- a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h +++ b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h @@ -15,47 +15,9 @@ #ifndef MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_ #define MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_ -#include // NOLINT +#include "re2/re2.h" -#include "absl/base/call_once.h" - -namespace mediapipe { - -// Implements a subset of RE2 using std::regex_match. -class RE2 { - public: - RE2(const std::string& pattern) : std_regex_(pattern) {} - static bool FullMatch(std::string text, const RE2& re) { - return std::regex_match(text, re.std_regex_); - } - static bool PartialMatch(std::string text, const RE2& re) { - return std::regex_search(text, re.std_regex_); - } - static int GlobalReplace(std::string* text, const RE2& re, - const std::string& rewrite) { - std::smatch sm; - std::regex_search(*text, sm, re.std_regex_); - *text = std::regex_replace(*text, re.std_regex_, rewrite); - return std::max(0, static_cast(sm.size()) - 1); - } - - private: - std::regex std_regex_; -}; - -// Implements LazyRE2 using absl::call_once. -class LazyRE2 { - public: - RE2& operator*() const { - absl::call_once(once_, [&]() { ptr_ = new RE2(pattern_); }); - return *ptr_; - } - RE2* operator->() const { return &**this; } - const char* pattern_; - mutable RE2* ptr_; - mutable absl::once_flag once_; -}; - -} // namespace mediapipe +using re2::LazyRE2; +using re2::RE2; #endif // MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_