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