diff options
| author | 2022-05-06 15:06:56 +0100 | |
|---|---|---|
| committer | 2022-05-06 15:53:08 +0100 | |
| commit | f7c041f5605bcfa09ed040f897b2615da6209594 (patch) | |
| tree | ee54a3657624cde242e7be20d0afcc927114201b /src/modules/m_regex_stdlib.cpp | |
| parent | Fix matching case-insensitive human regex patterns. (diff) | |
| download | inspircd++-f7c041f5605bcfa09ed040f897b2615da6209594.tar.gz inspircd++-f7c041f5605bcfa09ed040f897b2615da6209594.tar.bz2 inspircd++-f7c041f5605bcfa09ed040f897b2615da6209594.zip | |
Implement support for regex capture groups.
Diffstat (limited to 'src/modules/m_regex_stdlib.cpp')
| -rw-r--r-- | src/modules/m_regex_stdlib.cpp | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/modules/m_regex_stdlib.cpp b/src/modules/m_regex_stdlib.cpp index 0f2d31a61..191625221 100644 --- a/src/modules/m_regex_stdlib.cpp +++ b/src/modules/m_regex_stdlib.cpp @@ -54,6 +54,22 @@ public: { return std::regex_search(text, regex); } + + std::optional<Regex::MatchCollection> Matches(const std::string& text) override + { + std::smatch matches; + if (!std::regex_search(text, matches, regex)) + return std::nullopt; + + Regex::Captures captures(matches.size()); + for (const auto& match : matches) + captures.push_back(match); + + // The stdregex engine does not support named captures. + static const Regex::NamedCaptures unusednc; + + return Regex::MatchCollection(std::move(captures), unusednc); + } }; class StdLibEngine final |
