My app has user defined regular expression patterns which may contain up to 3 capturing groups. Is there a better way to implement the following code?
std::string glyph1, glyph2, glyph3;
switch (regex.NumberOfCapturingGroups())
{
case 0:
default:
found = regex.PartialMatch(word);
break;
case 1:
found = regex.PartialMatch(word, &glyph1);
break;
case 2:
found = regex.PartialMatch(word, &glyph1, &glyph2);
break;
case 3:
found = regex.PartialMatch(word, &glyph1, &glyph2, &glyph3);
break;
}
if (found) {
// ...
}
Unfortunately, the returned value is false if the regex would match but there were less capturing groups then requested.
Aucun commentaire:
Enregistrer un commentaire