Skip to content
Permalink
Browse files

update

  • Loading branch information...
neurobin committed Aug 17, 2018
1 parent ae60242 commit 28078a305034792b3c0b44c8d3e0e7efd2a500e4
Showing with 77 additions and 4 deletions.
  1. +22 −1 README
  2. +22 −1 README.md
  3. +2 −2 src/jpcre2.hpp
  4. +31 −0 src/testme.cpp
23 README
@@ -854,6 +854,27 @@ Example multi-threaded programs are provided in *src/test_pthread.cpp* and *src/
* To use JPCRE2 in its full capability (including `>=C++11` features), use latest compilers with full `C++11` support.
* If you do not use `>=C++11`, you will be OK with older compilers.

<a name="examples"></a>

# Examples

Examples and test programs are available in `src/test*.cpp` files.

File | Containing examples
---- | -------------------
`test0.cpp` | Handling `std::string` and `std::wstring`.
`test16.cpp` | Performing regex match and regex replace with `std::wstring` and `std::u16string`.
`test32.cpp` | Performing regex match and regex replace with `std::wstring` and `std::u32string`.
`test_match.cpp` | Performing regex match against a pattern and getting the match count and match results. Shows how to iterate over the match results to get the captured groups/substrings.
`test_match2.cpp` | Contains an example to take subject string, pattern and modifier from user input and perform regex match using JPCRE2.
`testmd.cpp` | Examples of working with modifier table.
`testme.cpp` | Examples of using MatchEvaluator to perform replace.
`test_replace.cpp` | Example of doing regex replace.
`test_replace2.cpp` | Contains an example to take subject string, replacement string, modifier and pattern from user input and perform regex replace with JPCRE2
`test_pthread.cpp` | Multi threaded examples with POSIX pthread.
`teststdthread.cpp` | Multi threaded examples with `std::thread`.
`test_shorts.cpp` | Contains some short examples.

<a name="short-examples"></a>

# Short examples
@@ -1086,7 +1107,7 @@ Option | Details

# Contributing/Pull request

> Please do all pull requests against the master branch. The default branch is 'release' which is not where continuous development of jpcre2 is done.
**Please do all pull requests against the master branch. The default branch is 'release' which is not where continuous development of JPCRE2 is done.**

If you find any error in the documentation or confusing/misleading use of terms, or anything that cathces your eye and feels not right, please open an issue in the [issue page](https://github.com/jpcre2/jpcre2/issues). Or if you want to fix it and do pull request then use the master branch.

@@ -854,6 +854,27 @@ Example multi-threaded programs are provided in *src/test_pthread.cpp* and *src/
* To use JPCRE2 in its full capability (including `>=C++11` features), use latest compilers with full `C++11` support.
* If you do not use `>=C++11`, you will be OK with older compilers.
<a name="examples"></a>
# Examples
Examples and test programs are available in `src/test*.cpp` files.
File | Containing examples
---- | -------------------
`test0.cpp` | Handling `std::string` and `std::wstring`.
`test16.cpp` | Performing regex match and regex replace with `std::wstring` and `std::u16string`.
`test32.cpp` | Performing regex match and regex replace with `std::wstring` and `std::u32string`.
`test_match.cpp` | Performing regex match against a pattern and getting the match count and match results. Shows how to iterate over the match results to get the captured groups/substrings.
`test_match2.cpp` | Contains an example to take subject string, pattern and modifier from user input and perform regex match using JPCRE2.
`testmd.cpp` | Examples of working with modifier table.
`testme.cpp` | Examples of using MatchEvaluator to perform replace.
`test_replace.cpp` | Example of doing regex replace.
`test_replace2.cpp` | Contains an example to take subject string, replacement string, modifier and pattern from user input and perform regex replace with JPCRE2
`test_pthread.cpp` | Multi threaded examples with POSIX pthread.
`teststdthread.cpp` | Multi threaded examples with `std::thread`.
`test_shorts.cpp` | Contains some short examples.
<a name="short-examples"></a>
# Short examples
@@ -1086,7 +1107,7 @@ Option | Details

# Contributing/Pull request

> Please do all pull requests against the master branch. The default branch is 'release' which is not where continuous development of jpcre2 is done.
**Please do all pull requests against the master branch. The default branch is 'release' which is not where continuous development of JPCRE2 is done.**

If you find any error in the documentation or confusing/misleading use of terms, or anything that cathces your eye and feels not right, please open an issue in the [issue page](https://github.com/jpcre2/jpcre2/issues). Or if you want to fix it and do pull request then use the master branch.

@@ -1,7 +1,7 @@
/* *****************************************************************************
* ******************* C++ wrapper for PCRE2 Library ****************************
* *****************************************************************************
* Copyright (c) 2015-2017 Md. Jahidul Hamid
* Copyright (c) 2015-2018 Md. Jahidul Hamid
*
* -----------------------------------------------------------------------------
* Redistribution and use in source and binary forms, with or without
@@ -1853,7 +1853,7 @@ struct select{
///Return pointer to the match context that was previously set with setMatchContext().
///Handling memory is the callers' responsibility.
///@return pointer to the match context (default: null).
MatchContext* getMatchContext(){
virtual MatchContext* getMatchContext(){
return mcontext;
}

@@ -67,6 +67,15 @@ String callback7(const jp::NumSub& m1, const jp::MapNas& m2, const jp::MapNtn& m
return "("+m1[0]+"/"+mn2["total"]+"/"+toString(mn3["total"])+"/$0)";
}

//The following is an example how you can use start_offset and
//end_offset inside callback
jpcre2::VecOff const* start_offset, *end_offset;
size_t offset_count = 0;
String callback_using_offset(const jp::NumSub& m1, void*, void* ){
size_t count = offset_count++;
return "(m[0]: "+ m1[0] + "/" + "start_offset: " + toString((*start_offset)[count]) + "/end_offset: " + toString((*end_offset)[count]);
}

int main(){
jp::Regex re("(?<total>(?<w>\\w+)(?<s>\\s+)(?<d>\\d+))", "n");
jp::RegexReplace rr(&re);
@@ -183,6 +192,28 @@ int main(){
std::cout<<"\n\n### callback7: \n"<<cme.setCallback(callback7).setFindAll(false).replace(false);


/* *********************************************************************
* The following is an example how you can use start_offset and
* end_offset inside callback
* *********************************************************************/

start_offset = cme.getMatchStartOffsetVector();
end_offset = cme.getMatchEndOffsetVector();
std::cout<<"\n\n### callback_using_offset: \n"<<cme.setCallback(callback_using_offset).replace();

#if __cplusplus >= 201103L
//using lambda
jpcre2::VecOff const * so = cme.getMatchStartOffsetVector();
jpcre2::VecOff const * eo = cme.getMatchEndOffsetVector();
size_t off_count = 0;
cme.setCallback(
[&](const jp::NumSub& m1, void*, void*){
size_t count = off_count++;
return "(m[0]: "+ m1[0] + "/" + "start_offset: " + toString((*so)[count]) + "/end_offset: " + toString((*eo)[count]) + ")";
}
);
std::cout<<"\n\n### lambda_callback_using_offset: \n"<<cme.replace();
#endif


/* *****************************************************************

0 comments on commit 28078a3

Please sign in to comment.
You can’t perform that action at this time.