| From b7928899936522b3d03aef1cca566030510f6a01 Mon Sep 17 00:00:00 2001 |
| From: Robert Ogden <robertogden@chromium.org> |
| Date: Wed, 26 Jul 2023 11:24:47 -0700 |
| Subject: [PATCH] use re2 instead of std regex |
| |
| --- |
| .../src/mediapipe/framework/deps/re2.h | 42 ++----------------- |
| 1 file changed, 3 insertions(+), 39 deletions(-) |
| |
| diff --git a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h |
| index 61f7985ee62fe..4079d9c0d1916 100644 |
| --- a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h |
| +++ b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h |
| @@ -15,45 +15,9 @@ |
| #ifndef MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_ |
| #define MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_ |
| |
| -#include <regex> // NOLINT |
| +#include "re2/re2.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<int>(sm.size()) - 1); |
| - } |
| - |
| - private: |
| - std::regex std_regex_; |
| -}; |
| - |
| -// Implements LazyRE2 using std::call_once. |
| -class LazyRE2 { |
| - public: |
| - RE2& operator*() const { |
| - std::call_once(once_, [&]() { ptr_ = new RE2(pattern_); }); |
| - return *ptr_; |
| - } |
| - RE2* operator->() const { return &**this; } |
| - const char* pattern_; |
| - mutable RE2* ptr_; |
| - mutable std::once_flag once_; |
| -}; |
| - |
| -} // namespace mediapipe |
| +using re2::LazyRE2; |
| +using re2::RE2; |
| |
| #endif // MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_ |
| -- |
| 2.41.0.487.g6d72f3e995-goog |
| |