bloaty/src/re.h
Go to the documentation of this file.
1 // Copyright 2020 Google Inc. All Rights Reserved.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 
15 #ifndef BLOATY_RE_H_
16 #define BLOATY_RE_H_
17 
18 #include <string>
19 
20 #ifdef USE_RE2
21 #include "re2/re2.h"
22 #endif
23 
24 #include "absl/base/attributes.h"
25 
26 namespace bloaty {
27 
28 #ifdef USE_RE2
29 class ReImpl {
30  public:
31  ReImpl(const char* pattern) : re2_(pattern){};
32  ReImpl(const std::string& pattern) : re2_(pattern){};
33  bool ok() { return re2_.ok(); }
34 
35  static bool Extract(std::string text, const ReImpl& re, std::string rewrite,
36  std::string* out) {
37  return RE2::Extract(text, re.re2_, rewrite, out);
38  }
39  template <typename... A>
40  static bool PartialMatch(const std::string& text, const ReImpl& re,
41  A&&... a) {
42  return RE2::PartialMatch(text, re.re2_, a...);
43  }
44 
45  static int GlobalReplace(std::string* str, const ReImpl& re,
46  std::string rewrite) {
47  return RE2::GlobalReplace(str, re.re2_, rewrite);
48  }
49  static bool Replace(std::string* str, const ReImpl& re, std::string rewrite) {
50  return RE2::Replace(str, re.re2_, rewrite);
51  }
52 
53  private:
54  RE2 re2_;
55 };
56 #else
57 }
58 
60 static void _abort() { throw "No support for regular expressions"; }
61 
62 namespace bloaty {
63 class ReImpl {
64  public:
65  ReImpl(const char*) { _abort(); }
66  ReImpl(const std::string&) { _abort(); }
67  bool ok() { _abort(); }
68 
70  static bool Extract(std::string, const ReImpl&, std::string, std::string*) {
71  _abort();
72  }
73  template <typename... A>
75  const ReImpl&, A&&...) {
76  _abort();
77  }
79  static int GlobalReplace(std::string*, const ReImpl&, std::string) {
80  _abort();
81  }
83  static bool Replace(std::string*, const ReImpl&, std::string) { _abort(); }
84 
85  private:
86 };
87 #endif
88 
89 } // namespace bloaty
90 
91 #endif // BLOATY_RE_H_
xds_interop_client.str
str
Definition: xds_interop_client.py:487
bloaty::ReImpl::ReImpl
ReImpl(const char *)
Definition: bloaty/src/re.h:65
bloaty
Definition: bloaty.cc:69
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
ABSL_ATTRIBUTE_NORETURN
#define ABSL_ATTRIBUTE_NORETURN
Definition: abseil-cpp/absl/base/attributes.h:203
check_tracer_sanity.pattern
pattern
Definition: check_tracer_sanity.py:25
testing::internal::string
::std::string string
Definition: bloaty/third_party/protobuf/third_party/googletest/googletest/include/gtest/internal/gtest-port.h:881
a
int a
Definition: abseil-cpp/absl/container/internal/hash_policy_traits_test.cc:88
bloaty::ReImpl::ReImpl
ReImpl(const std::string &)
Definition: bloaty/src/re.h:66
_abort
static ABSL_ATTRIBUTE_NORETURN void _abort()
Definition: bloaty/src/re.h:60
gen_server_registered_method_bad_client_test_body.text
def text
Definition: gen_server_registered_method_bad_client_test_body.py:50
bloaty::ReImpl::Replace
static ABSL_ATTRIBUTE_NORETURN bool Replace(std::string *, const ReImpl &, std::string)
Definition: bloaty/src/re.h:83
bloaty::ReImpl::Extract
static ABSL_ATTRIBUTE_NORETURN bool Extract(std::string, const ReImpl &, std::string, std::string *)
Definition: bloaty/src/re.h:70
bloaty::ReImpl::PartialMatch
static ABSL_ATTRIBUTE_NORETURN bool PartialMatch(const std::string &, const ReImpl &, A &&...)
Definition: bloaty/src/re.h:74
bloaty::ReImpl::ok
bool ok()
Definition: bloaty/src/re.h:67
grpc_ruby_generator::Replace
std::string Replace(std::string s, const std::string &from, const std::string &to)
Definition: ruby_generator_string-inl.h:52
bloaty::ReImpl
Definition: bloaty/src/re.h:63
A
Definition: miscompile_with_no_unique_address_test.cc:23
bloaty::ReImpl::GlobalReplace
static ABSL_ATTRIBUTE_NORETURN int GlobalReplace(std::string *, const ReImpl &, std::string)
Definition: bloaty/src/re.h:79


grpc
Author(s):
autogenerated on Fri May 16 2025 03:00:00