private Match GenerateMatch (Regex regex)
{
int n_caps, first_mark_index;
Group g;
GetGroupInfo (0, out first_mark_index, out n_caps);
// Avoid fully populating the Match instance if not needed
if (!needs_groups_or_captures)
return new Match (regex, this, text, text_end, 0, marks [first_mark_index].Index, marks [first_mark_index].Length);
Match retval = new Match (regex, this, text, text_end, groups.Length,
marks [first_mark_index].Index, marks [first_mark_index].Length, n_caps);
PopulateGroup (retval, first_mark_index, n_caps);
for (int gid = 1; gid < groups.Length; ++ gid) {
GetGroupInfo (gid, out first_mark_index, out n_caps);
if (first_mark_index < 0) {
g = Group.Fail;
} else {
g = new Group (text, marks [first_mark_index].Index, marks [first_mark_index].Length, n_caps);
PopulateGroup (g, first_mark_index, n_caps);
}
retval.Groups.SetValue (g, gid);
}
return retval;
}