2
* Copyright (C) 2005-2008 Tommi Maekitalo
4
* This program is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
9
* This program is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with this program; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21
#include "cxxtools/regex.h"
28
unsigned RegexSMatch::size() const
31
for (n = 0; n < 10 && matchbuf[n].rm_so >= 0; ++n)
37
std::string RegexSMatch::get(unsigned n) const
39
return str.substr(matchbuf[n].rm_so, matchbuf[n].rm_eo - matchbuf[n].rm_so);
42
std::string RegexSMatch::format(const std::string& s) const
56
for (std::string::const_iterator it = s.begin(); it != s.end(); ++it)
77
ret = std::string(s.begin(), it - 1);
78
regoff_t s = matchbuf[ch - '0'].rm_so;
79
regoff_t e = matchbuf[ch - '0'].rm_eo;
81
ret.append(str, s, e-s);
91
else if (state == '\\')
100
unsigned s = matchbuf[ch - '0'].rm_so;
101
unsigned e = matchbuf[ch - '0'].rm_eo;
102
if (s >= 0 && e >= 0)
103
ret.append(str, s, e-s);
136
void Regex::checkerr(int ret) const
141
regerror(ret, expr.getPointer(), errbuf, sizeof(errbuf));
142
throw std::runtime_error(errbuf);
146
bool Regex::match(const std::string& str_, int eflags) const
149
return match(str_, smatch, eflags);
152
bool Regex::match(const std::string& str_, RegexSMatch& smatch, int eflags) const
155
int ret = regexec(expr.getPointer(), str_.c_str(),
156
sizeof(smatch.matchbuf) / sizeof(regmatch_t), smatch.matchbuf, eflags);
158
if (ret ==REG_NOMATCH)