Add methods for extracting specific regex captures.

This commit is contained in:
Sadie Powell 2022-06-28 14:00:14 +01:00
parent 0f84414b39
commit a0850bc53f

View File

@ -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; }
};