]> git.tdb.fi Git - libs/core.git/blob - source/strings/regmatch.cpp
f81be1a5225b09886579df8a92582078609b2a61
[libs/core.git] / source / strings / regmatch.cpp
1 /* $Id$
2
3 This file is part of libmspstrings
4 Copyright © 2007 Mikko Rasa
5 Distributed under the LGPL
6 */
7
8 #include <msp/core/except.h>
9 #include "regmatch.h"
10
11 using namespace std;
12
13 namespace Msp {
14
15 RegMatch::RegMatch(const string &str, const GroupArray &g):
16         groups(g)
17 {
18         for(GroupArray::iterator i=groups.begin(); i!=groups.end(); ++i)
19                 if(i->match)
20                 {
21                         i->length = i->end-i->begin;
22                         i->str = str.substr(i->begin, i->length);
23                 }
24 }
25
26 const RegMatch::Group &RegMatch::group(unsigned i) const
27 {
28         if(i>=groups.size())
29                 throw InvalidParameterValue("Group index out of range");
30         return groups[i];
31 }
32
33 } // namespace Msp