aboutsummaryrefslogtreecommitdiffstats
path: root/include/modules
diff options
context:
space:
mode:
authorGravatar Sadie Powell2022-06-28 14:00:14 +0100
committerGravatar Sadie Powell2022-06-28 14:00:14 +0100
commita0850bc53f1a86adf4507ece2cd13923134f45fb (patch)
tree6953d62f4dd3cab46f48aeb3a8a3979b24b9ce75 /include/modules
parentMove the userip module to contrib. (diff)
Add methods for extracting specific regex captures.
Diffstat (limited to 'include/modules')
-rw-r--r--include/modules/regex.h19
1 files changed, 19 insertions, 0 deletions
diff --git a/include/modules/regex.h b/include/modules/regex.h
index 55bfe19b8..71a3906e1 100644
--- a/include/modules/regex.h
+++ b/include/modules/regex.h
@@ -174,9 +174,28 @@ public:
{
}
+ /** Retrieves a specific captured substring by index.
+ * @param idx The index of the captured substring to return.
+ * The requested captured substring or std::nullopt if it does not exist.
+ */
+ const std::optional<std::string> GetCapture(size_t idx) const
+ {
+ return captures.size() > idx ? std::nullopt : std::make_optional(captures[idx]);
+ }
+
/** Retrieves the substrings that were captured. */
const Captures& GetCaptures() const { return captures; }
+ /** Retrieves a specific captured substring by index.
+ * @param name The name of the captured substring to return.
+ * The requested captured substring or std::nullopt if it does not exist.
+ */
+ const std::optional<std::string> GetNamedCapture(const std::string& name) const
+ {
+ auto capture = namedcaptures.find(name);
+ return capture == namedcaptures.end() ? std::nullopt : std::make_optional(capture->second);
+ }
+
/** Retrieves the substrings that were captured by name. */
const NamedCaptures& GetNamedCaptures() const { return namedcaptures; }
};