MCPcopy Create free account
hub / github.com/apache/trafficserver / Regex

Class Regex

include/tsutil/Regex.h:89–156  ·  view source on GitHub ↗

@brief Wrapper for PCRE2 regular expression.

Source from the content-addressed store, hash-verified

87
88/// @brief Wrapper for PCRE2 regular expression.
89class Regex
90{
91public:
92 Regex() = default;
93 Regex(Regex const &) = delete; // No copying.
94 Regex(Regex &&that) noexcept;
95 ~Regex();
96
97 /** Compile the @a pattern into a regular expression.
98 *
99 * @param pattern Source pattern for regular expression (null terminated).
100 * @param flags Compilation flags.
101 * @return @a true if compiled successfully, @a false otherwise.
102 *
103 * @a flags should be the bitwise @c or of @c REFlags values.
104 */
105 bool compile(std::string_view pattern, uint32_t flags = 0);
106
107 /** Compile the @a pattern into a regular expression.
108 *
109 * @param pattern Source pattern for regular expression (null terminated).
110 * @param error String to receive error message.
111 * @param erroffset Pointer to integer to receive error offset.
112 * @param flags Compilation flags.
113 * @return @a true if compiled successfully, @a false otherwise.
114 *
115 * @a flags should be the bitwise @c or of @c REFlags values.
116 */
117 bool compile(std::string_view pattern, std::string &error, int &erroffset, unsigned flags = 0);
118
119 /** Execute the regular expression.
120 *
121 * @param subject String to match against.
122 * @return @c true if the pattern matched, @a false if not.
123 *
124 * It is safe to call this method concurrently on the same instance of @a this.
125 */
126 bool exec(std::string_view subject) const;
127
128 /** Execute the regular expression.
129 *
130 * @param subject String to match against.
131 * @param matches Place to store the capture groups.
132 * @return @c The number of capture groups. < 0 if an error occurred. 0 if the number of Matches is too small.
133 *
134 * It is safe to call this method concurrently on the same instance of @a this.
135 *
136 * Each capture group takes 3 elements of @a ovector, therefore @a ovecsize must
137 * be a multiple of 3 and at least three times the number of desired capture groups.
138 */
139 int exec(std::string_view subject, RegexMatches &matches) const;
140
141 /// @return The number of capture groups in the compiled pattern.
142 int get_capture_count();
143
144private:
145 /// @internal This effectively wraps a void* so that we can avoid requiring the pcre2.h include for the user of the Regex
146 /// API (see Regex.cc).

Callers 1

do_remapFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected