 |
JPCRE2
10.32.01
C++ wrapper for PCRE2 library
|
#include <iostream>
#include "jpcre2.hpp"
#include <cassert>
A test suit to check for code validity.
Goals:
- Check Validity of output for different inputs
- Memory check
- Segfault check
- coverage
This program will exit with 0 if all test passes, otherwise exit with a non-zero status when error occurs.
#include <iostream>
#include <cassert>
#if __cplusplus >= 201103L
#endif
int main(){
assert(rmc.
match() == 9);
assert(vec_numc[8][0] == "9");
assert(vec_numc[8][1] == "9");
assert(vec_nasc[8]["digit"] == "9");
assert(vec_ntnc[8]["digit"] == 1);
assert(rec.
replace(
"123456789",
"d$1") ==
"d123456789");
size_t counter;
assert(rec.
replace(
"123456789",
"d$1",
"g") ==
"d1d2d3d4d5d6d7d8d9");
assert(rec.
replace(
"123456789",
"d$1",
"g", &counter) ==
"d1d2d3d4d5d6d7d8d9");
JPCRE2_ASSERT(counter == 9,
"replace counter gave wrong result");
std::string s1 = "123456789";
JPCRE2_ASSERT(s1 ==
"d123456789",
"preplace didn't modify the string in-place");
JPCRE2_ASSERT(s1 ==
"d",
"Match evaluator with preplace did not work");
std::string rs = "d";
s1 = "123456789";
assert(rmw.
match() == 9);
assert(vec_numw[8][0] == L"9");
assert(vec_numw[8][1] == L"9");
assert(vec_nasw[8][L"digit"] == L"9");
assert(vec_ntnw[8][L"digit"] == 1);
assert(rew.
replace(L
"123456789", L
"d$1") == L
"d123456789");
assert(rew.
replace(L
"123456789", L
"d$1",
"g") == L
"d1d2d3d4d5d6d7d8d9");
assert(rew.
replace(L
"123456789", L
"d$1",
"g", &counter) == L
"d1d2d3d4d5d6d7d8d9");
JPCRE2_ASSERT(counter == 9,
"replace counter gave wrong result");
#if __cplusplus >= 201103L
assert(rm16.
match() == 9);
assert(vec_num16[8][0] == u"9");
assert(vec_num16[8][1] == u"9");
assert(vec_nas16[8][u"digit"] == u"9");
assert(vec_ntn16[8][u"digit"] == 1);
assert(re16.
replace(u
"123456789", u
"d$1") == u
"d123456789");
assert(re16.
replace(u
"123456789", u
"d$1",
"g") == u
"d1d2d3d4d5d6d7d8d9");
assert(re16.
replace(u
"123456789", u
"d$1",
"g", &counter) == u
"d1d2d3d4d5d6d7d8d9");
JPCRE2_ASSERT(counter == 9,
"replace counter gave wrong result");
assert(rm32.
match() == 9);
assert(vec_num32[8][0] == U"9");
assert(vec_num32[8][1] == U"9");
assert(vec_nas32[8][U"digit"] == U"9");
assert(vec_ntn32[8][U"digit"] == 1);
assert(re32.
replace(U
"123456789", U
"d$1") == U
"d123456789");
assert(re32.
replace(U
"123456789", U
"d$1",
"g") == U
"d1d2d3d4d5d6d7d8d9");
assert(re32.
replace(U
"123456789", U
"d$1",
"g", &counter) == U
"d1d2d3d4d5d6d7d8d9");
JPCRE2_ASSERT(counter == 9,
"replace counter gave wrong result");
#endif
std::string s("");
md2.c_str();
#if __cplusplus >= 201103L
#endif
return 0;
}
- Author
- Md Jahidul Hamid
String replace(String const &mains, String const &repl, Modifier const &mod="", SIZE_T *counter=0)
Perform regex replace and return the replaced string using a temporary replace object.
Definition: jpcre2.hpp:4285
virtual RegexMatch & setNameToNumberMapVector(VecNtN *v)
Set a pointer to the name to number map vector.
Definition: jpcre2.hpp:1732
virtual RegexMatch & setNamedSubstringVector(VecNas *v)
Set a pointer to the named substring vector.
Definition: jpcre2.hpp:1721
SIZE_T preplace(String *mains, String const &repl, Modifier const &mod="")
Perl compatible replace method.
Definition: jpcre2.hpp:4332
virtual RegexMatch & setSubject(String const &s)
Set the subject string for match.
Definition: jpcre2.hpp:1762
String nreplace(bool do_match=true, Uint jro=0, SIZE_T *counter=0)
Perform regex replace with this match evaluator.
Definition: jpcre2.hpp:4591
MatchEvaluator & setSubject(String const &s)
Call RegexMatch::setSubject(String const &s).
Definition: jpcre2.hpp:2662
String replace(void)
Perform regex replace by retrieving subject string, replacement string, modifier and other options fr...
Definition: jpcre2.hpp:4654
virtual RegexMatch & setRegexObject(Regex const *r)
Set the associated regex object.
Definition: jpcre2.hpp:1699
Regex & setPattern(String const &re)
Set the pattern string to compile.
Definition: jpcre2.hpp:3999
SIZE_T getLastReplaceCount()
Get the number of replacement in last replace operation.
Definition: jpcre2.hpp:3196
RegexReplace & setReplaceWith(String const &s)
Set the replacement string.
Definition: jpcre2.hpp:3261
virtual RegexMatch & setModifier(Modifier const &s)
Set the modifier (resets all JPCRE2 and PCRE2 options) by calling RegexMatch::changeModifier().
Definition: jpcre2.hpp:1790
std::vector< NumSub > VecNum
Vector of matches with numbered substrings.
Definition: jpcre2.hpp:1279
Provides public constructors to create RegexReplace objects.
Definition: jpcre2.hpp:2890
std::string str() const
Returns the modifier string.
Definition: jpcre2.hpp:651
RegexReplace & setRegexObject(Regex const *r)
Set the associated Regex object.
Definition: jpcre2.hpp:3216
#define JPCRE2_ASSERT(cond, msg)
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
virtual SIZE_T match(void)
Perform match operation using info from class variables and return the match count and store the resu...
Definition: jpcre2.hpp:4776
Class to take a std::string modifier value with null safety.
Definition: jpcre2.hpp:634
RegexReplace & setSubject(String const &s)
Set the subject string for replace.
Definition: jpcre2.hpp:3227
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
RegexReplace & setModifier(Modifier const &s)
Set the modifier string (resets all JPCRE2 and PCRE2 options) by calling RegexReplace::changeModifier...
Definition: jpcre2.hpp:3285
void compile(void)
Compile pattern using info from class variables.
Definition: jpcre2.hpp:4422
virtual RegexMatch & setNumberedSubstringVector(VecNum *v)
Set a pointer to the numbered substring vector.
Definition: jpcre2.hpp:1710
struct to select the types.
Definition: jpcre2.hpp:1238
SIZE_T preplace(void)
Perl compatible replace method.
Definition: jpcre2.hpp:3451
std::vector< MapNtN > VecNtN
Vector of substring name to substring number map.
Definition: jpcre2.hpp:1275
Provides public constructors to create RegexMatch objects.
Definition: jpcre2.hpp:1375
std::vector< MapNas > VecNas
Vector of matches with named substrings.
Definition: jpcre2.hpp:1273
This class inherits RegexMatch and provides a similar functionality.
Definition: jpcre2.hpp:2135