xuboying / pcre2plus Goto Github PK
View Code? Open in Web Editor NEWregular expression, pcre, pcre2, c++
License: Other
regular expression, pcre, pcre2, c++
License: Other
Support macro to turn on/off throwing exception
reference:
http://www.cplusplus.com/doc/tutorial/exceptions/
http://en.cppreference.com/w/cpp/regex/regex_error
Need to find the source code in pcre2 to get constants of err.codes
std::tuple<std::string, size_t> re::RegexObject::subn(const std::string & repl, const std::string & Str, size_t count){
if (this->m_pattern == ""){
return std::make_tuple("", -1);
}
pcre2_match_data_8 * match_data = pcre2_match_data_create_from_pattern_8(m_re, NULL);
std::string Str1 = Str;
size_t option = PCRE2_SUBSTITUTE_OVERFLOW_LENGTH | PCRE2_SUBSTITUTE_EXTENDED;
if (count == 0){
option |= PCRE2_SUBSTITUTE_GLOBAL;
}
PCRE2_UCHAR8 * outputbuffer = nullptr;
PCRE2_SIZE outlength = Str1.length() * 2;
PCRE2_SIZE * p_outlength = &outlength;
int c = 0;
size_t i = 0;
while(i <= count){
outputbuffer = (PCRE2_UCHAR8 *)malloc(sizeof(PCRE2_UCHAR8 *) * outlength);
int ret = pcre2_substitute_8(
(pcre2_code_8 *)m_re,
(PCRE2_SPTR8)Str1.c_str(),
Str1.size(), // * sizeof(char),
0,
(int)option,
match_data,
NULL,
(PCRE2_SPTR8)repl.c_str(),
repl.size(),
(PCRE2_UCHAR8 *)outputbuffer,
p_outlength
);
if (ret == 0){
break;
}
if (ret < 0){
if (ret == PCRE2_ERROR_NOMEMORY){
free(outputbuffer);
outputbuffer = nullptr;
continue;
}
else{
re::lasterror = ret;
return std::make_tuple("", -1);
}
}
std::string r((char *)outputbuffer);
r = r.substr(0, outlength);
Str1 = r;
free(outputbuffer);
outputbuffer = nullptr;
c += ret;
i++;
}
Str1.append("\0"); //<---------------------------
pcre2_match_data_free_8(match_data);
return std::make_tuple(Str1,c);
The current code is using string copy in finditer which is a bit slow
The behaviour shall be changed to use string reference
VERSION: a128925 and older
workaround: (?:.|[\x0a\x0d])
No callback function implemented yet
chomp
chop
trim
ltrim
rtrim
reverse
join
buidin regex patterns e.g ip address
avoid using ++*x.get()
VERSION: a128925 and older
pcre2_match
hanging for long string
the result is different from python standard for empty pattern or non-existing result
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.