]> git.tdb.fi Git - libs/core.git/blob - source/strings/regmatch.cpp
Use C++11 features with containers
[libs/core.git] / source / strings / regmatch.cpp
1 #include <stdexcept>
2 #include "regmatch.h"
3
4 using namespace std;
5
6 namespace Msp {
7
8 RegMatch::RegMatch(const string &str, const vector<Group> &grps):
9         groups(grps)
10 {
11         for(Group &g: groups)
12                 if(g.match)
13                 {
14                         g.length = g.end-g.begin;
15                         g.str = str.substr(g.begin, g.length);
16                 }
17 }
18
19 const RegMatch::Group &RegMatch::group(unsigned i) const
20 {
21         if(i>=groups.size())
22                 throw out_of_range("RegMatch::group");
23         return groups[i];
24 }
25
26 } // namespace Msp