1 /*---------------------------------------------------------------------\
3 | |__ / \ / / . \ . \ |
8 \---------------------------------------------------------------------*/
9 /** \file zypp/base/Regex.cc
17 #include "zypp/base/Regex.h"
19 using namespace zypp::str;
21 regex::regex(const std::string& str, int flags)
24 if (regcomp(&m_preg, str.c_str(), REG_EXTENDED))
28 regex::~regex() throw()
34 bool zypp::str::regex_match(const std::string& s, smatch& matches, const regex& regex)
36 bool r = regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
38 matches.match_str = s;
42 bool zypp::str::regex_match(const std::string& s, const regex& regex)
44 return !regexec(®ex.m_preg, s.c_str(), 0, NULL, 0);
47 bool zypp::str::regex_search(const std::string& s, smatch& matches, const regex& regex)
49 bool r= regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
51 matches.match_str = s;
57 memset(&pmatch, -1, sizeof(pmatch));
60 std::string smatch::operator[](unsigned i) const
62 if (i < 12 && pmatch[i].rm_so != -1)
63 return match_str.substr(pmatch[i].rm_so, pmatch[i].rm_eo-pmatch[i].rm_so);
68 unsigned smatch::size() const
71 while (matches < 12 && pmatch[matches+1].rm_so != -1) {
72 // std::cout << "match[" << matches << "]: *" << (*this)[matches
73 // +1] << "*" << std::endl;
79 /*---------------------------------------------------------------------\
81 | |__ / \ / / . \ . \ |
84 | /_____||_| |_| |_| |
86 \---------------------------------------------------------------------*/
87 /** \file zypp/base/Regex.cc
95 #include "zypp/base/Regex.h"
97 using namespace zypp::str;
99 regex::regex(const std::string& str, int flags)
102 if (regcomp(&m_preg, str.c_str(), REG_EXTENDED))
106 regex::~regex() throw()
112 bool zypp::str::regex_match(const std::string& s, smatch& matches, const regex& regex)
114 bool r = regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
116 matches.match_str = s;
120 bool zypp::str::regex_match(const std::string& s, const regex& regex)
122 return !regexec(®ex.m_preg, s.c_str(), 0, NULL, 0);
125 bool zypp::str::regex_search(const std::string& s, smatch& matches, const regex& regex)
127 bool r= regex.m_valid && !regexec(®ex.m_preg, s.c_str(), 12, &matches.pmatch[0], 0);
129 matches.match_str = s;
135 memset(&pmatch, -1, sizeof(pmatch));
138 std::string smatch::operator[](unsigned i) const
140 if (i < 12 && pmatch[i].rm_so != -1)
141 return match_str.substr(pmatch[i].rm_so, pmatch[i].rm_eo-pmatch[i].rm_so);
142 return std::string();
146 unsigned smatch::size() const
148 unsigned matches = 0;
149 while (matches < 12 && pmatch[matches+1].rm_so != -1) {
150 // std::cout << "match[" << matches << "]: *" << (*this)[matches
151 // +1] << "*" << std::endl;