Skip to content

Commit

Permalink
Add match evaluator
Browse files Browse the repository at this point in the history
  • Loading branch information
neurobin committed Jan 22, 2017
1 parent a79e775 commit af198d2
Show file tree
Hide file tree
Showing 12 changed files with 796 additions and 110 deletions.
7 changes: 7 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Change Log for JPCRE2
--------------------

Version 10.28.12 -
-----------------------------------------------

* Add match evaluator (close feature request #9)
* Improve getter functions


Version 10.28.11 - Mon Dec 5 09:58:35 UTC 2016
-----------------------------------------------

Expand Down
4 changes: 2 additions & 2 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/config/compile \
$(top_srcdir)/config/install-sh $(top_srcdir)/config/ltmain.sh \
$(top_srcdir)/config/missing AUTHORS COPYING ChangeLog INSTALL \
NEWS README config/compile config/config.guess \
config/config.sub config/install-sh config/ltmain.sh \
config/missing
config/config.sub config/depcomp config/install-sh \
config/ltmain.sh config/missing
DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
distdir = $(PACKAGE)-$(VERSION)
top_distdir = $(distdir)
Expand Down
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@


41 changes: 41 additions & 0 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,47 @@ The `RegexReplace` class stores a pointer to its' associated Regex object. If th

**Note:** This independent replace object and the replace object you get from `jp::Regex::initReplace()` or `jp::Regex::getReplaceObject()` are not the same.

<a name="matchevaluator"></a>

### MatchEvaluator

There's another replace function (`jp::RegexReplace::nreplace()`) that takes a MatchEvaluator with a callback function. It's required when you have to create the replacement strings dynamically according to some criteria.

The class `jp::MatchEvaluator` implements several constructor overloads to take different callback functions i.e you can pass a callback function with its' constructor when instantiating a object of this class.

The callback function takes exactly three positional arguments. If you don't need one or two arguments, you may pass `void*` in their respective positions in the argument list.

**Examples:**

```cpp
jp::String myme1(jp::NumSub m, void*, void*){
return "("+m[0]+")";
}

int main(){
jp::Regex re("(?<total>\\w+)", "n");
jp::RegexReplace rr(&re);

String s3 = "I am ঋ আা a string 879879 fdsjkll ১ ২ ৩ ৪ অ আ ক খ গ ঘ আমার সোনার বাংলা";

rr.setSubject(s3)
.setPcre2Option(PCRE2_SUBSTITUTE_GLOBAL);

#if __cplusplus >= 201103L
//example with lambda
std::cout<<"\n\n### Lambda\n"<<rr.nreplace(
jp::MatchEvaluator([](jp::NumSub m1, jp::MapNas m2, void*)
{
return "("+m1[0]+"/"+m2["total"]+")";
}));
#endif
std::cout<<"\n\n### 1\n"<<rr.nreplace(jp::MatchEvaluator(myme1));
return 0;
}
```

Detailed examples are in the testme.cpp file.

<a name="modifiers"></a>

# Modifiers
Expand Down
41 changes: 41 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,47 @@ The `RegexReplace` class stores a pointer to its' associated Regex object. If th
**Note:** This independent replace object and the replace object you get from `jp::Regex::initReplace()` or `jp::Regex::getReplaceObject()` are not the same.
<a name="matchevaluator"></a>
### MatchEvaluator
There's another replace function (`jp::RegexReplace::nreplace()`) that takes a MatchEvaluator with a callback function. It's required when you have to create the replacement strings dynamically according to some criteria.
The class `jp::MatchEvaluator` implements several constructor overloads to take different callback functions i.e you can pass a callback function with its' constructor when instantiating a object of this class.
The callback function takes exactly three positional arguments. If you don't need one or two arguments, you may pass `void*` in their respective positions in the argument list.
**Examples:**
```cpp
jp::String myme1(jp::NumSub m, void*, void*){
return "("+m[0]+")";
}
int main(){
jp::Regex re("(?<total>\\w+)", "n");
jp::RegexReplace rr(&re);
String s3 = "I am ঋ আা a string 879879 fdsjkll ১ ২ ৩ ৪ অ আ ক খ গ ঘ আমার সোনার বাংলা";
rr.setSubject(s3)
.setPcre2Option(PCRE2_SUBSTITUTE_GLOBAL);
#if __cplusplus >= 201103L
//example with lambda
std::cout<<"\n\n### Lambda\n"<<rr.nreplace(
jp::MatchEvaluator([](jp::NumSub m1, jp::MapNas m2, void*)
{
return "("+m1[0]+"/"+m2["total"]+")";
}));
#endif
std::cout<<"\n\n### 1\n"<<rr.nreplace(jp::MatchEvaluator(myme1));
return 0;
}
```

Detailed examples are in the testme.cpp file.

<a name="modifiers"></a>

# Modifiers
Expand Down
4 changes: 2 additions & 2 deletions autogen.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/sh
#autoreconf -v -i
autoreconf --force --install
autoreconf -v -i
#autoreconf --force --install
20 changes: 10 additions & 10 deletions configure
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#! /bin/sh
# Guess values for system-dependent variables and create Makefiles.
# Generated by GNU Autoconf 2.69 for jpcre2 10.28.11.
# Generated by GNU Autoconf 2.69 for jpcre2 10.28.12.
#
# Report bugs to <https://github.com/jpcre2/jpcre2/issues>.
#
Expand Down Expand Up @@ -590,8 +590,8 @@ MAKEFLAGS=
# Identity of this package.
PACKAGE_NAME='jpcre2'
PACKAGE_TARNAME='jpcre2'
PACKAGE_VERSION='10.28.11'
PACKAGE_STRING='jpcre2 10.28.11'
PACKAGE_VERSION='10.28.12'
PACKAGE_STRING='jpcre2 10.28.12'
PACKAGE_BUGREPORT='https://github.com/jpcre2/jpcre2/issues'
PACKAGE_URL=''

Expand Down Expand Up @@ -1363,7 +1363,7 @@ if test "$ac_init_help" = "long"; then
# Omit some internal or obsolete options to make the list less imposing.
# This message is too long to be a string in the A/UX 3.1 sh.
cat <<_ACEOF
\`configure' configures jpcre2 10.28.11 to adapt to many kinds of systems.
\`configure' configures jpcre2 10.28.12 to adapt to many kinds of systems.

Usage: $0 [OPTION]... [VAR=VALUE]...

Expand Down Expand Up @@ -1434,7 +1434,7 @@ fi

if test -n "$ac_init_help"; then
case $ac_init_help in
short | recursive ) echo "Configuration of jpcre2 10.28.11:";;
short | recursive ) echo "Configuration of jpcre2 10.28.12:";;
esac
cat <<\_ACEOF

Expand Down Expand Up @@ -1556,7 +1556,7 @@ fi
test -n "$ac_init_help" && exit $ac_status
if $ac_init_version; then
cat <<\_ACEOF
jpcre2 configure 10.28.11
jpcre2 configure 10.28.12
generated by GNU Autoconf 2.69

Copyright (C) 2012 Free Software Foundation, Inc.
Expand Down Expand Up @@ -2230,7 +2230,7 @@ cat >config.log <<_ACEOF
This file contains any messages produced by compilers while
running configure, to aid debugging if configure makes a mistake.

It was created by jpcre2 $as_me 10.28.11, which was
It was created by jpcre2 $as_me 10.28.12, which was
generated by GNU Autoconf 2.69. Invocation command line was

$ $0 $@
Expand Down Expand Up @@ -3096,7 +3096,7 @@ fi

# Define the identity of the package.
PACKAGE='jpcre2'
VERSION='10.28.11'
VERSION='10.28.12'


cat >>confdefs.h <<_ACEOF
Expand Down Expand Up @@ -18906,7 +18906,7 @@ cat >>$CONFIG_STATUS <<\_ACEOF || ac_write_fail=1
# report actual input values of CONFIG_FILES etc. instead of their
# values after options handling.
ac_log="
This file was extended by jpcre2 $as_me 10.28.11, which was
This file was extended by jpcre2 $as_me 10.28.12, which was
generated by GNU Autoconf 2.69. Invocation command line was

CONFIG_FILES = $CONFIG_FILES
Expand Down Expand Up @@ -18963,7 +18963,7 @@ _ACEOF
cat >>$CONFIG_STATUS <<_ACEOF || ac_write_fail=1
ac_cs_config="`$as_echo "$ac_configure_args" | sed 's/^ //; s/[\\""\`\$]/\\\\&/g'`"
ac_cs_version="\\
jpcre2 config.status 10.28.11
jpcre2 config.status 10.28.12
configured by $0, generated by GNU Autoconf 2.69,
with options \\"\$ac_cs_config\\"

Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ AC_CONFIG_MACRO_DIR([m4])
include([ax_cxx_compile_stdcxx.m4])
include([acx_pthread.m4])

AC_INIT([jpcre2], [10.28.11], [https://github.com/jpcre2/jpcre2/issues])
AC_INIT([jpcre2], [10.28.12], [https://github.com/jpcre2/jpcre2/issues])
AC_CONFIG_AUX_DIR(config)
AC_CONFIG_SRCDIR([src/jpcre2.hpp])
#AC_CONFIG_HEADERS([config.h])
Expand Down
16 changes: 13 additions & 3 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ EXTRA_DIST += \
test32.cpp \
test0.cpp \
test.cpp \
testio.cpp
testio.cpp \
testme.cpp

include_HEADERS = \
jpcre2.hpp
Expand Down Expand Up @@ -106,8 +107,8 @@ test0_CXXFLAGS = \
$(AM_CXXFLAGS) \
$(AM_LDFLAGS)

noinst_PROGRAMS += test testio
TESTS += test testio
noinst_PROGRAMS += test testio testme
TESTS += test testio testme

#Building test
test_SOURCES = \
Expand All @@ -127,6 +128,15 @@ testio_CXXFLAGS = \
$(AM_LDFLAGS) \
$(COVERAGE_FLAGS)

#Building testme
testme_SOURCES = \
testme.cpp \
$(JPCRE2_SOURCES)
testme_CXXFLAGS = \
$(AM_CXXFLAGS) \
$(AM_LDFLAGS) \
$(COVERAGE_FLAGS)


endif

Expand Down

0 comments on commit af198d2

Please sign in to comment.