Skip to content

Commit 90e9290

Browse files
committed
Redesigned native functions implementation.
1 parent 06e9b60 commit 90e9290

File tree

4 files changed

+200
-83
lines changed

4 files changed

+200
-83
lines changed

com.ibm.streamsx.regex/com.ibm.streamsx.regex.re2/native.function/function.xml

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,28 @@
55
<cppNamespaceName>regex</cppNamespaceName>
66
<functions>
77
<function>
8-
<description>Tries to match the whole string with the pattern (overloaded version, called after the initial pattern is already compiled).</description>
9-
<prototype>public boolean regexFullMatch(rstring str)</prototype>
8+
<description>Compiles regex pattern and indexes it.</description>
9+
<prototype>&lt;enum E> public boolean regexCompile(rstring pattern, E patternIndex)</prototype>
1010
</function>
1111
<function>
12-
<description sampleUri="">Tries to match the whole string with the pattern.</description>
13-
<prototype>public boolean regexFullMatch(rstring str, rstring pattern)</prototype>
12+
<description>Compiles regex pattern and indexes it, additionally allows to control max memory allocated.</description>
13+
<prototype>&lt;enum E> public boolean regexCompile(rstring pattern, E patternIndex, int32 maxmem)</prototype>
1414
</function>
1515
<function>
16-
<description>Tries to match the whole string with the pattern (additionally allows to control max memory allocated).</description>
17-
<prototype>public boolean regexFullMatch(rstring str, rstring pattern, int32 maxmem)</prototype>
16+
<description>Tries to match the whole string with the pattern - doesn't use compiled regex.</description>
17+
<prototype>public boolean regexFullMatch(rstring str, rstring pattern)</prototype>
1818
</function>
1919
<function>
20-
<description>Tries to match the string with the pattern (overloaded version, called after the initial pattern is already compiled).</description>
21-
<prototype>public boolean regexPartialMatch(rstring str)</prototype>
20+
<description>Tries to match the whole string with the pattern - uses compiled regex by it's index.</description>
21+
<prototype>&lt;enum E> public boolean regexFullMatch(rstring str, E patternIndex)</prototype>
2222
</function>
2323
<function>
24-
<description>Tries to match the string with the pattern.</description>
24+
<description>Tries to match the string with the pattern - doesn't use compiled regex.</description>
2525
<prototype>public boolean regexPartialMatch(rstring str, rstring pattern)</prototype>
2626
</function>
2727
<function>
28-
<description>Tries to match the string with the pattern (additionally allows to control max memory allocated).</description>
29-
<prototype>public boolean regexPartialMatch(rstring str, rstring pattern, int32 maxmem)</prototype>
30-
</function>
31-
<function>
32-
<description>Tries to match the string with the pattern.</description>
33-
<prototype>public boolean regexSimpleMatch(rstring str, rstring pattern)</prototype>
28+
<description>Tries to match the string with the pattern - uses compiled regex by it's index.</description>
29+
<prototype>&lt;enum E> public boolean regexPartialMatch(rstring str, E patternIndex)</prototype>
3430
</function>
3531
</functions>
3632
<dependencies>

com.ibm.streamsx.regex/impl/include/Regex.h

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,42 @@ using namespace std;
2020

2121
namespace regex {
2222

23+
template<typename Index>
2324
inline RE2::Options& getRE2Options(int maxmem){
2425
static RE2::Options options;
2526
options.set_log_errors(false);
2627
options.set_max_mem(maxmem);
2728
return options;
2829
}
2930

30-
inline RE2& getRE2(const string & pattern, int maxmem){
31-
static RE2 regex(pattern, getRE2Options(maxmem));
31+
template<typename Index>
32+
inline RE2& getRE2(const string & pattern="", int maxmem=1000000){
33+
static RE2 regex(pattern, getRE2Options<Index>(maxmem));
3234
return regex;
3335
}
3436

35-
inline bool regexFullMatch(const string & str, const string & pattern="", int maxmem=1000000){
36-
return RE2::FullMatch(str, getRE2(pattern, maxmem)) == 1;
37+
template<typename Index>
38+
inline void regexCompile(const SPL::rstring & pattern, const Index & patternIndex, int maxmem=1000000){
39+
getRE2<Index>(pattern, maxmem);
3740
}
3841

39-
inline bool regexPartialMatch(const string & str, const string & pattern="", int maxmem=1000000){
40-
return RE2::PartialMatch(str, getRE2(pattern, maxmem)) == 1;
42+
inline bool regexFullMatch(const string & str, const SPL::rstring & pattern){
43+
return RE2::FullMatch(str, pattern) == 1;
4144
}
4245

43-
inline bool regexSimpleMatch(const string & str, const string & pattern){
46+
template<typename Index>
47+
inline bool regexFullMatch(const string & str, const Index & patternIndex){
48+
return RE2::FullMatch(str, getRE2<Index>()) == 1;
49+
}
50+
51+
inline bool regexPartialMatch(const string & str, const SPL::rstring & pattern){
4452
return RE2::PartialMatch(str, pattern) == 1;
4553
}
54+
55+
template<typename Index>
56+
inline bool regexPartialMatch(const string & str, const Index & patternIndex){
57+
return RE2::PartialMatch(str, getRE2<Index>()) == 1;
58+
}
4659
}
4760

4861
#endif /* REGEX_H_ */

com.ibm.streamsx.regex/info.xml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<info:toolkitInfoModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common"
3-
xmlns:info="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo">
4-
<info:identity>
5-
<info:name>com.ibm.streamsx.regex</info:name>
2+
<info:toolkitInfoModel xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:info="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo">
3+
<info:identity>
4+
<info:name>com.ibm.streamsx.regex</info:name>
65
<info:description>
76
Support for [http://code.google.com/p/re2|RE2] regular expression library.
87

@@ -16,10 +15,10 @@ This toolkit provides several operators and native finctions to run RE2 engine i
1615
Each operator/native function implements partial or full regex match.
1716

1817
**Third-party libraries**
19-
* This toolkit embeds RE2 headers/libraries under impl/&lt;include|lib&gt;.
18+
* This toolkit embeds RE2 headers/libraries under impl/&lt;include|lib>.
2019
</info:description>
21-
<info:version>1.0.0</info:version>
22-
<info:requiredProductVersion>3.1.0</info:requiredProductVersion>
23-
</info:identity>
24-
<info:dependencies/>
20+
<info:version>1.2.0</info:version>
21+
<info:requiredProductVersion>3.2.1</info:requiredProductVersion>
22+
</info:identity>
23+
<info:dependencies/>
2524
</info:toolkitInfoModel>

0 commit comments

Comments
 (0)