1
#pragma once
2

            
3
#include "envoy/type/matcher/v3/regex.pb.h"
4

            
5
#include "source/common/common/regex.h"
6

            
7
#include "absl/status/statusor.h"
8

            
9
namespace Envoy {
10
namespace Matcher {
11

            
12
class RegexReplace {
13
public:
14
  RegexReplace(Regex::CompiledMatcherPtr regex, std::string&& substitution)
15
13
      : regex_(std::move(regex)), substitution_(std::move(substitution)) {}
16

            
17
  // Create a RegexReplace from a RegexMatchAndSubstitute proto message.
18
  //
19
  // If the proto has no pattern, returns nullopt.
20
  static absl::StatusOr<RegexReplace>
21
  create(Regex::Engine& engine, const ::envoy::type::matcher::v3::RegexMatchAndSubstitute& proto);
22

            
23
  // Returns a string of the input string with the regex replace applied.
24
  std::string apply(absl::string_view in) const;
25

            
26
private:
27
  Regex::CompiledMatcherPtr regex_{};
28
  const std::string substitution_{};
29
};
30

            
31
} // namespace Matcher
32
} // namespace Envoy