userver: userver/utils/regex.hpp Source File
Loading...
Searching...
No Matches
regex.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/utils/regex.hpp
4/// @brief @copybrief utils::regex
5
6#include <string>
7
8#include <userver/utils/fast_pimpl.hpp>
9
10USERVER_NAMESPACE_BEGIN
11
12namespace utils {
13
14/// @ingroup userver_universal userver_containers
15///
16/// @brief Small alias for boost::regex / std::regex without huge includes
17class regex final {
18 public:
19 regex();
20 explicit regex(std::string_view pattern);
21
22 ~regex();
23
24 regex(const regex&);
25 regex(regex&&) noexcept;
26
27 regex& operator=(const regex&);
28 regex& operator=(regex&&) noexcept;
29
30 std::string str() const;
31
32 private:
33 struct Impl;
34 utils::FastPimpl<Impl, 16, 8> impl_;
35
36 friend bool regex_match(std::string_view str, const regex& pattern);
37 friend bool regex_search(std::string_view str, const regex& pattern);
38 friend std::string regex_replace(std::string_view str, const regex& pattern,
39 std::string_view repl);
40};
41
42/// @brief Determines whether the regular expression matches the entire target
43/// character sequence
44bool regex_match(std::string_view str, const regex& pattern);
45
46/// @brief Determines whether the regular expression matches anywhere in the
47/// target character sequence
48bool regex_search(std::string_view str, const regex& pattern);
49
50/// @brief Create a new string where all regular expression matches replaced
51/// with repl
52std::string regex_replace(std::string_view str, const regex& pattern,
53 std::string_view repl);
54
55} // namespace utils
56
57USERVER_NAMESPACE_END