blob: 5a1bbb625676fbd3fa3c3a9c10a9336adf209fb0 [file] [log] [blame]
Robert Ogdenaa6cc932023-07-26 19:54:541From b7928899936522b3d03aef1cca566030510f6a01 Mon Sep 17 00:00:00 2001
2From: Robert Ogden <robertogden@chromium.org>
3Date: Wed, 26 Jul 2023 11:24:47 -0700
4Subject: [PATCH] use re2 instead of std regex
5
6---
7 .../src/mediapipe/framework/deps/re2.h | 42 ++-----------------
8 1 file changed, 3 insertions(+), 39 deletions(-)
9
10diff --git a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h
11index 61f7985ee62fe..4079d9c0d1916 100644
12--- a/third_party/mediapipe/src/mediapipe/framework/deps/re2.h
13+++ b/third_party/mediapipe/src/mediapipe/framework/deps/re2.h
14@@ -15,45 +15,9 @@
15 #ifndef MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_
16 #define MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_
17
18-#include <regex> // NOLINT
19+#include "re2/re2.h"
20
21-namespace mediapipe {
22-
John Abd-El-Malek08071803e2023-09-07 07:51:2223-// Implements a subset of RE2 using std::regex_match.
Robert Ogdenaa6cc932023-07-26 19:54:5424-class RE2 {
25- public:
26- RE2(const std::string& pattern) : std_regex_(pattern) {}
27- static bool FullMatch(std::string text, const RE2& re) {
28- return std::regex_match(text, re.std_regex_);
29- }
30- static bool PartialMatch(std::string text, const RE2& re) {
31- return std::regex_search(text, re.std_regex_);
32- }
33- static int GlobalReplace(std::string* text, const RE2& re,
34- const std::string& rewrite) {
35- std::smatch sm;
36- std::regex_search(*text, sm, re.std_regex_);
37- *text = std::regex_replace(*text, re.std_regex_, rewrite);
38- return std::max(0, static_cast<int>(sm.size()) - 1);
39- }
40-
41- private:
42- std::regex std_regex_;
43-};
44-
45-// Implements LazyRE2 using std::call_once.
46-class LazyRE2 {
47- public:
48- RE2& operator*() const {
49- std::call_once(once_, [&]() { ptr_ = new RE2(pattern_); });
50- return *ptr_;
51- }
52- RE2* operator->() const { return &**this; }
53- const char* pattern_;
54- mutable RE2* ptr_;
55- mutable std::once_flag once_;
56-};
57-
58-} // namespace mediapipe
59+using re2::LazyRE2;
60+using re2::RE2;
61
62 #endif // MEDIAPIPE_FRAMEWORK_DEPS_RE2_H_
63--
642.41.0.487.g6d72f3e995-goog
65