Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
neurobin committed Aug 13, 2017
1 parent 9a5f595 commit 9b2f1ce
Show file tree
Hide file tree
Showing 7 changed files with 205 additions and 83 deletions.
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ Version 10.31.01 -
* Remove macro JPCRE2_DISABLE_CHAR1632
* Remove macro JPCRE2_DISABLE_CODE_UNIT_WIDTH_VALIDATION
* Remove ConvInt and ConvUTF (including Convert16 and Convert32)
* Add perl compatible replace method: preplace()
* Add macro JPCRE2_NDEBUG



Expand Down
227 changes: 172 additions & 55 deletions src/jpcre2.hpp

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/testcovme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ int main(){
//The following (uncomment if you wanna test) will give you assertion failure, because the callback1 only populates NumSub vector,
//but callback2 requires pre-exisiting (due to the 'false' argument to nreplace()) MapNas data:
cme.reset().setSubject(&s3).setRegexObject(&re).setFindAll().setCallback(callback1).nreplace();
//~ std::cout<<"\n\n### callback2: \n"<<cme.setCallback(callback2).nreplace(false); //Assertion failure.
std::cout<<"\n\n### callback2: \n"<<cme.setCallback(callback2).nreplace(false); //Assertion failure.

return 0;
}
21 changes: 20 additions & 1 deletion src/testio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,34 @@ int main(){
assert(rec.replace("123456789", "d$1", "g", &counter) == "d1d2d3d4d5d6d7d8d9");
JPCRE2_ASSERT(counter == 9, "replace counter gave wrong result");

rrc.setSubject("123456789").setRegexObject(&rec).setReplaceWith("d$1");
rrc.setSubject("123456789").setRegexObject(&rec).setReplaceWith("d$0");
rrc.replace();
JPCRE2_ASSERT(rrc.preplace() == 1, "replace counter gave wrong result");
std::string s1 = "123456789";
rrc.setSubject(&s1).setRegexObject(&rec).setReplaceWith("d$0");
JPCRE2_ASSERT(rrc.preplace() == 1, "replace counter gave wrong result");
JPCRE2_ASSERT(s1 == "d123456789", "preplace didn't modify the string in-place");
JPCRE2_ASSERT(rrc.getLastReplaceCount() == 1, "replace counter gave wrong result");
rrc.setRegexObject(0).replace();
JPCRE2_ASSERT(rrc.getLastReplaceCount() == 0, "replace counter gave wrong result");

rec.compile("\\w*\\K\\w*");
jpc::MatchEvaluator(&rec).setSubject("----fdsjflfsd8fds68").nreplace();

jpc::MatchEvaluator mec; //erase callback
rec.compile("\\d");
rrc.setRegexObject(&rec).setSubject(&s1).setModifier("g");
JPCRE2_ASSERT(rrc.preplace(mec) == 9, "Invalid replace count with match evaluator");
JPCRE2_ASSERT(s1 == "d", "Match evaluator with preplace did not work");
std::string rs = "d";
JPCRE2_ASSERT(rec.preplace("123456789", "d", "g") == 9, "Error in rec.preplace");
JPCRE2_ASSERT(rec.preplace("123456789", &rs, "g") == 9, "Error in rec.preplace");
s1 = "123456789";
JPCRE2_ASSERT(rec.preplace(&s1, "d", "g") == 9, "Error in rec.preplace");
JPCRE2_ASSERT(rec.preplace(&s1, &rs, "g") == 0, "Error in rec.preplace");
JPCRE2_ASSERT(s1 == "ddddddddd", "Error in rec.preplace");


////////////////////////////////////////////////////////////////////

//////////////////////// Check with std::wstring ///////////////////
Expand Down
3 changes: 2 additions & 1 deletion src/testmd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ int main(){

//now bind the table with the object
jp::Regex re;
re.setModifierTable(&mdt);
std::string m = "I";
re.setModifierTable(&mdt).changeModifier(m, true);

//let's perform a compile
re.compile("JPCRE2","I");
Expand Down
3 changes: 1 addition & 2 deletions src/testme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

#if __cplusplus >= 201103L
//In >=C++11 you can pass an optional template parameter to select the map container that will be
//used for MapNas and MapNtn
//used for MapNas and MapNtn instead of std::map
typedef jpcre2::select<char, std::unordered_map> jp;
#else
typedef jpcre2::select<char> jp;
Expand Down Expand Up @@ -99,7 +99,6 @@ int main(){
std::cout<<"\n\n### 7\n"<<rr.nreplace(jp::MatchEvaluator(callback7));

//MatchEvaluator itself has an nreplace() function:
//Actually the RegexReplace::nreplace(MatchEvaluator me) is just a wrapper of MatchEvaluator::nreplace().
std::cout<<"\n\n### 7 Calling directly MatchEvaluator::nreplace()\n"
<<jp::MatchEvaluator(callback7)
.setSubject(&s3)
Expand Down
30 changes: 7 additions & 23 deletions src/testmv.cpp
Original file line number Diff line number Diff line change
@@ -1,30 +1,14 @@
#include <iostream>
#include <pthread.h>
#include "jpcre2.hpp"
#include <cstring>

#include <unistd.h>

typedef jpcre2::select<char> jp;
void fun(size_t* x){
std::cout<<"\n"<<(*x);
}

int main(){
jpcre2::Modifier a("");

jp::RegexReplace rr;
std::cout<<rr.getLastReplaceCount(); //should print 0

jp::Regex re("\\d");
rr.setSubject("123456789")
.setRegexObject(&re)
.setReplaceWith("#")
.addModifier("g")
.replace();

std::cout<<rr.getLastReplaceCount(); //should print 9

re.compile("(\\d");
std::cout<<"\n"<<re.getErrorMessage()<<"at offset: "<<re.getErrorOffset();
int rc=0;
fun((size_t*)&rc); //should print 0, but outputs random value

size_t c=0;
fun(&c); //prints 0
return 0;

}

0 comments on commit 9b2f1ce

Please sign in to comment.