1
#include "source/common/matcher/regex_replace.h"
2

            
3
namespace Envoy {
4
namespace Matcher {
5

            
6
absl::StatusOr<RegexReplace>
7
RegexReplace::create(Regex::Engine& engine,
8
14
                     const ::envoy::type::matcher::v3::RegexMatchAndSubstitute& proto) {
9
14
  ASSERT(!proto.pattern().regex().empty(), "invalid RegexMatchAndSubstitute message");
10
14
  auto regex_or_status = Regex::Utility::parseRegex(proto.pattern(), engine);
11
14
  RETURN_IF_NOT_OK(regex_or_status.status());
12
13
  return RegexReplace(std::move(regex_or_status).value(), std::string{proto.substitution()});
13
14
}
14

            
15
17
std::string RegexReplace::apply(absl::string_view in) const {
16
17
  return regex_->replaceAll(in, substitution_);
17
17
}
18

            
19
} // namespace Matcher
20
} // namespace Envoy