Coverage Report

Created: 2023-12-14 13:59

/src/bloaty/src/re.h
Line
Count
Source (jump to first uncovered line)
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
0
  ReImpl(const char* pattern) : re2_(pattern){};
32
0
  ReImpl(const std::string& pattern) : re2_(pattern){};
33
0
  bool ok() { return re2_.ok(); }
34
35
  static bool Extract(std::string text, const ReImpl& re, std::string rewrite,
36
0
                      std::string* out) {
37
0
    return RE2::Extract(text, re.re2_, rewrite, out);
38
0
  }
39
  template <typename... A>
40
  static bool PartialMatch(const std::string& text, const ReImpl& re,
41
0
                           A&&... a) {
42
0
    return RE2::PartialMatch(text, re.re2_, a...);
43
0
  }
Unexecuted instantiation: bool bloaty::ReImpl::PartialMatch<>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bloaty::ReImpl const&)
Unexecuted instantiation: bool bloaty::ReImpl::PartialMatch<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*>(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&, bloaty::ReImpl const&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >*&&)
44
45
  static int GlobalReplace(std::string* str, const ReImpl& re,
46
0
                           std::string rewrite) {
47
0
    return RE2::GlobalReplace(str, re.re2_, rewrite);
48
0
  }
49
0
  static bool Replace(std::string* str, const ReImpl& re, std::string rewrite) {
50
0
    return RE2::Replace(str, re.re2_, rewrite);
51
0
  }
52
53
 private:
54
  RE2 re2_;
55
};
56
#else
57
}
58
59
ABSL_ATTRIBUTE_NORETURN
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
69
  ABSL_ATTRIBUTE_NORETURN
70
  static bool Extract(std::string, const ReImpl&, std::string, std::string*) {
71
    _abort();
72
  }
73
  template <typename... A>
74
  ABSL_ATTRIBUTE_NORETURN static bool PartialMatch(const std::string&,
75
                                                   const ReImpl&, A&&...) {
76
    _abort();
77
  }
78
  ABSL_ATTRIBUTE_NORETURN
79
  static int GlobalReplace(std::string*, const ReImpl&, std::string) {
80
    _abort();
81
  }
82
  ABSL_ATTRIBUTE_NORETURN
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_