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
14class match_results;
15
16/// @ingroup userver_universal userver_containers
17///
18/// @brief Small alias for boost::regex / std::regex without huge includes
19class regex final {
20public:
21 regex();
22 explicit regex(std::string_view pattern);
23
24 ~regex();
25
26 regex(const regex&);
27 regex(regex&&) noexcept;
28
29 regex& operator=(const regex&);
30 regex& operator=(regex&&) noexcept;
31
32 bool operator==(const regex&) const;
33
34 std::string str() const;
35
36private:
37 struct Impl;
38 utils::FastPimpl<Impl, 16, 8> impl_;
39
40 friend class match_results;
41 friend bool regex_match(std::string_view str, const regex& pattern);
42 friend bool regex_match(std::string_view str, match_results& m, const regex& pattern);
43 friend bool regex_search(std::string_view str, const regex& pattern);
44 friend bool regex_search(std::string_view str, match_results& m, const regex& pattern);
45 friend std::string regex_replace(std::string_view str, const regex& pattern, std::string_view repl);
46};
47
48/// @ingroup userver_universal userver_containers
49///
50/// @brief Small alias for boost::smatch / std::regex without huge includes
51class match_results final {
52public:
53 match_results();
54
55 ~match_results();
56
57 match_results(const match_results&);
58
59 match_results& operator=(const match_results&);
60
61 std::size_t size() const;
62 std::string_view operator[](int sub) const;
63
64private:
65 struct Impl;
66 utils::FastPimpl<Impl, 80, 8> impl_;
67
68 friend bool regex_match(std::string_view str, const regex& pattern);
69 friend bool regex_match(std::string_view str, match_results& m, const regex& pattern);
70 friend bool regex_search(std::string_view str, const regex& pattern);
71 friend bool regex_search(std::string_view str, match_results& m, const regex& pattern);
72 friend std::string regex_replace(std::string_view str, const regex& pattern, std::string_view repl);
73};
74
75/// @brief Determines whether the regular expression matches the entire target
76/// character sequence
77bool regex_match(std::string_view str, const regex& pattern);
78
79/// @brief Returns true if the specified regular expression matches
80/// the whole of the input. Fills in what matched in m.
81bool regex_match(std::string_view str, match_results& m, const regex& pattern);
82
83/// @brief Determines whether the regular expression matches anywhere in the
84/// target character sequence. Fills in what matched in m
85bool regex_search(std::string_view str, match_results& m, const regex& pattern);
86
87/// @brief Determines whether the regular expression matches anywhere in the
88/// target character sequence
89bool regex_search(std::string_view str, const regex& pattern);
90
91/// @brief Create a new string where all regular expression matches replaced
92/// with repl
93std::string regex_replace(std::string_view str, const regex& pattern, std::string_view repl);
94
95} // namespace utils
96
97USERVER_NAMESPACE_END