File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ #include < Ark/VM/Value/Dict.hpp>
12#include < module.hpp>
23#include < utils.hpp>
34
45#include < vector>
6+ #include < ranges>
57
68#include < re2/re2.h>
79
@@ -13,9 +15,21 @@ namespace Regex
1315
1416 Value toValue (const Match& match, const std::string& text)
1517 {
16- if (const auto & span = match.spans .front (); !span.empty )
17- return Value (text.substr (span.start , span.size ));
18- return Nil;
18+ internal::Dict dict;
19+ const auto & span = match.spans .front ();
20+ if (!span.empty )
21+ dict.set (Value (" match" ), Value (text.substr (span.start , span.size )));
22+ else
23+ dict.set (Value (" match" ), Nil);
24+ dict.set (Value (" start" ), Value (static_cast <int64_t >(span.start )));
25+ dict.set (Value (" end" ), Value (static_cast <int64_t >(span.size + span.start )));
26+
27+ Value groups (ValueType::List);
28+ for (const Span& s : match.spans | std::ranges::views::drop (1 ))
29+ groups.push_back (Value (text.substr (s.start , s.size )));
30+ dict.set (Value (" groups" ), groups);
31+
32+ return Value (std::move (dict));
1933 }
2034
2135 Value toValue (const MatchImpl_t& res)
You can’t perform that action at this time.
0 commit comments