JPCRE2  10.32.01
C++ wrapper for PCRE2 library
test_issue_29.cpp File Reference
#include <cassert>
#include <iostream>
#include "jpcre2.hpp"
+ Include dependency graph for test_issue_29.cpp:

Detailed Description

Test cases for issue 29 on Github

#include <cassert>
#include <iostream>
#include "jpcre2.hpp"
void test_match(jp::Regex &re, std::string const &subject) {
jp::VecNum matches;
bool out_of_range_occured = false;
size_t num = rm
.setRegexObject(&re)
.setNumberedSubstringVector(&matches)
.setSubject(subject)
.match();
assert(num > 0);
assert(matches[0][1] != "dummy"); // idx 1 should be accessible
assert(matches[0][2] != "dummy"); // idx 2 should be accessible
assert(matches[0][3] != "dummy"); // idx 3 should be accessible
try{
assert(matches[0].at(4) != "dummy"); // idx 4 should not be accessible
} catch(std::out_of_range const & e){
out_of_range_occured = true;
}
if(!out_of_range_occured){
std::cout<<"E: std::out_of_range exception was not thrown. vecnum has more capture groups than expected.\n";
exit(1);
}
}
int main(){
// check with a regex pattern with 3 capture groups
jp::Regex re("^(\\d+)([abc])?([XYZ])?$");
test_match(re, "42bZ");
test_match(re, "23Z");
test_match(re, "54b");
test_match(re, "13");
return 0;
}
Author
Md Jahidul Hamid
Moritz Bunkus
jpcre2::select::VecNum
std::vector< NumSub > VecNum
Vector of matches with numbered substrings.
Definition: jpcre2.hpp:1279
jpcre2.hpp
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
jpcre2::select::Regex
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
jpcre2::select
struct to select the types.
Definition: jpcre2.hpp:1238
jpcre2::select::RegexMatch
Provides public constructors to create RegexMatch objects.
Definition: jpcre2.hpp:1375