]> git.tdb.fi Git - libs/core.git/blob - source/regmatch.cpp
f08f08a7aa589b42a2de0db81d9d894fc88c10cc
[libs/core.git] / source / regmatch.cpp
1 #include <msp/core/error.h>
2 #include "regmatch.h"
3
4 using namespace std;
5
6 namespace Msp {
7
8 RegMatch::RegMatch(const string &str, const GroupArray &g):
9         groups(g)
10 {
11         for(GroupArray::iterator i=groups.begin(); i!=groups.end(); ++i)
12                 if(i->match)
13                 {
14                         i->length=i->end-i->begin;
15                         i->str=str.substr(i->begin, i->length);
16                 }
17 }
18
19 const RegMatch::Group &RegMatch::group(unsigned i) const
20 {
21         if(i>=groups.size())
22                 throw InvalidParameterValue("Group index out of range");
23         return groups[i];
24 }
25
26 } // namespace Msp