Skip to content

Commit 2fdc978

Browse files
committed
The functions now work on operator scope.
For PE scope static functions are introduced.
1 parent 5ce436a commit 2fdc978

File tree

3 files changed

+81
-7
lines changed

3 files changed

+81
-7
lines changed

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

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@
1212
<description>Compiles regex pattern and indexes it, additionally allows to control max memory allocated.</description>
1313
<prototype>&lt;enum E> public boolean regexCompile(rstring pattern, E patternIndex, int32 maxmem)</prototype>
1414
</function>
15+
<function>
16+
<description>Compiles regex pattern and indexes it - static version</description>
17+
<prototype>&lt;enum E> public boolean regexCompileStatic(rstring pattern, E patternIndex)</prototype>
18+
</function>
19+
<function>
20+
<description>Compiles regex pattern and indexes it - static version, additionally allows to control max memory allocated.</description>
21+
<prototype>&lt;enum E> public boolean regexCompileStatic(rstring pattern, E patternIndex, int32 maxmem)</prototype>
22+
</function>
1523
<function>
1624
<description>Tries to match the whole string with the pattern - doesn't use compiled regex.</description>
1725
<prototype>public boolean regexFullMatch(rstring str, rstring pattern)</prototype>
@@ -20,6 +28,10 @@
2028
<description>Tries to match the whole string with the pattern - uses compiled regex by it's index.</description>
2129
<prototype>&lt;enum E> public boolean regexFullMatch(rstring str, E patternIndex)</prototype>
2230
</function>
31+
<function>
32+
<description>Tries to match the whole string with the pattern - static version, uses compiled regex by it's index.</description>
33+
<prototype>&lt;enum E> public boolean regexFullMatchStatic(rstring str, E patternIndex)</prototype>
34+
</function>
2335
<function>
2436
<description>Tries to match the string with the pattern - doesn't use compiled regex.</description>
2537
<prototype>public boolean regexPartialMatch(rstring str, rstring pattern)</prototype>
@@ -28,6 +40,10 @@
2840
<description>Tries to match the string with the pattern - uses compiled regex by it's index.</description>
2941
<prototype>&lt;enum E> public boolean regexPartialMatch(rstring str, E patternIndex)</prototype>
3042
</function>
43+
<function>
44+
<description>Tries to match the string with the pattern - static version, uses compiled regex by it's index.</description>
45+
<prototype>&lt;enum E> public boolean regexPartialMatchStatic(rstring str, E patternIndex)</prototype>
46+
</function>
3147
</functions>
3248
<dependencies>
3349
<library>

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

Lines changed: 39 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,46 @@ using namespace std;
2020

2121
namespace regex {
2222

23-
template<typename Index>
23+
namespace {
24+
struct OperatorInstance {};
25+
}
26+
27+
template<typename Index, typename OP>
2428
inline RE2::Options& getRE2Options(int maxmem){
2529
static RE2::Options options;
26-
options.set_log_errors(false);
30+
options.set_log_errors(true);
2731
options.set_max_mem(maxmem);
2832
return options;
2933
}
3034

3135
template<typename Index>
36+
inline RE2::Options& getRE2OptionsStatic(int maxmem){
37+
static RE2::Options options;
38+
options.set_log_errors(true);
39+
options.set_max_mem(maxmem);
40+
return options;
41+
}
42+
43+
template<typename Index, typename OP>
3244
inline RE2& getRE2(const string & pattern="", int maxmem=1000000){
33-
static RE2 regex(pattern, getRE2Options<Index>(maxmem));
45+
static RE2 regex(pattern, getRE2Options<Index,OP>(maxmem));
46+
return regex;
47+
}
48+
49+
template<typename Index>
50+
inline RE2& getRE2Static(const string & pattern="", int maxmem=1000000){
51+
static RE2 regex(pattern, getRE2OptionsStatic<Index>(maxmem));
3452
return regex;
3553
}
3654

3755
template<typename Index>
3856
inline void regexCompile(const SPL::rstring & pattern, const Index & patternIndex, int maxmem=1000000){
39-
getRE2<Index>(pattern, maxmem);
57+
getRE2<Index,OperatorInstance>(pattern, maxmem);
58+
}
59+
60+
template<typename Index>
61+
inline void regexCompileStatic(const SPL::rstring & pattern, const Index & patternIndex, int maxmem=1000000){
62+
getRE2Static<Index>(pattern, maxmem);
4063
}
4164

4265
inline bool regexFullMatch(const string & str, const SPL::rstring & pattern){
@@ -45,7 +68,12 @@ namespace regex {
4568

4669
template<typename Index>
4770
inline bool regexFullMatch(const string & str, const Index & patternIndex){
48-
return RE2::FullMatch(str, getRE2<Index>()) == 1;
71+
return RE2::FullMatch(str, getRE2<Index,OperatorInstance>()) == 1;
72+
}
73+
74+
template<typename Index>
75+
inline bool regexFullMatchStatic(const string & str, const Index & patternIndex){
76+
return RE2::FullMatch(str, getRE2Static<Index>()) == 1;
4977
}
5078

5179
inline bool regexPartialMatch(const string & str, const SPL::rstring & pattern){
@@ -54,7 +82,12 @@ namespace regex {
5482

5583
template<typename Index>
5684
inline bool regexPartialMatch(const string & str, const Index & patternIndex){
57-
return RE2::PartialMatch(str, getRE2<Index>()) == 1;
85+
return RE2::PartialMatch(str, getRE2<Index,OperatorInstance>()) == 1;
86+
}
87+
88+
template<typename Index>
89+
inline bool regexPartialMatchStatic(const string & str, const Index & patternIndex){
90+
return RE2::PartialMatch(str, getRE2Static<Index>()) == 1;
5891
}
5992
}
6093

com.ibm.streamsx.regex/toolkit.xml

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?xml version="1.0" encoding="UTF-8" standalone="no" ?>
2-
<toolkitModel xmlns="http://www.ibm.com/xmlns/prod/streams/spl/toolkit" productVersion="4.0.0.0" xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:ti="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2+
<toolkitModel xmlns="http://www.ibm.com/xmlns/prod/streams/spl/toolkit" productVersion="4.0.1.0" xmlns:common="http://www.ibm.com/xmlns/prod/streams/spl/common" xmlns:ti="http://www.ibm.com/xmlns/prod/streams/spl/toolkitInfo" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
33

44
<toolkit name="com.ibm.streamsx.regex" requiredProductVersion="4.0.0" version="1.4.0">
55
<description>
@@ -178,6 +178,19 @@ RegexMatch operator has three custom output functions:
178178
<parameter name="patternIndex" type="E"/>
179179
<parameter name="maxmem" type="int32"/>
180180
</function>
181+
<function modelUriIndex="2" name="regexCompileStatic" native="true" public="true" returnType="boolean" uriIndex="0">
182+
<description>Compiles regex pattern and indexes it - static version</description>
183+
<prototype>&lt;enum E&gt; public boolean regexCompileStatic(rstring pattern, E patternIndex)</prototype>
184+
<parameter name="pattern" type="rstring"/>
185+
<parameter name="patternIndex" type="E"/>
186+
</function>
187+
<function modelUriIndex="2" name="regexCompileStatic" native="true" public="true" returnType="boolean" uriIndex="0">
188+
<description>Compiles regex pattern and indexes it - static version, additionally allows to control max memory allocated.</description>
189+
<prototype>&lt;enum E&gt; public boolean regexCompileStatic(rstring pattern, E patternIndex, int32 maxmem)</prototype>
190+
<parameter name="pattern" type="rstring"/>
191+
<parameter name="patternIndex" type="E"/>
192+
<parameter name="maxmem" type="int32"/>
193+
</function>
181194
<function modelUriIndex="2" name="regexFullMatch" native="true" public="true" returnType="boolean" uriIndex="0">
182195
<description>Tries to match the whole string with the pattern - doesn't use compiled regex.</description>
183196
<prototype>public boolean regexFullMatch(rstring str, rstring pattern)</prototype>
@@ -190,6 +203,12 @@ RegexMatch operator has three custom output functions:
190203
<parameter name="str" type="rstring"/>
191204
<parameter name="patternIndex" type="E"/>
192205
</function>
206+
<function modelUriIndex="2" name="regexFullMatchStatic" native="true" public="true" returnType="boolean" uriIndex="0">
207+
<description>Tries to match the whole string with the pattern - static version, uses compiled regex by it's index.</description>
208+
<prototype>&lt;enum E&gt; public boolean regexFullMatchStatic(rstring str, E patternIndex)</prototype>
209+
<parameter name="str" type="rstring"/>
210+
<parameter name="patternIndex" type="E"/>
211+
</function>
193212
<function modelUriIndex="2" name="regexPartialMatch" native="true" public="true" returnType="boolean" uriIndex="0">
194213
<description>Tries to match the string with the pattern - doesn't use compiled regex.</description>
195214
<prototype>public boolean regexPartialMatch(rstring str, rstring pattern)</prototype>
@@ -202,6 +221,12 @@ RegexMatch operator has three custom output functions:
202221
<parameter name="str" type="rstring"/>
203222
<parameter name="patternIndex" type="E"/>
204223
</function>
224+
<function modelUriIndex="2" name="regexPartialMatchStatic" native="true" public="true" returnType="boolean" uriIndex="0">
225+
<description>Tries to match the string with the pattern - static version, uses compiled regex by it's index.</description>
226+
<prototype>&lt;enum E&gt; public boolean regexPartialMatchStatic(rstring str, E patternIndex)</prototype>
227+
<parameter name="str" type="rstring"/>
228+
<parameter name="patternIndex" type="E"/>
229+
</function>
205230
</namespace>
206231
<sabFiles>
207232
<ti:include path="toolkit.xml" root="toolkitDir"/>

0 commit comments

Comments
 (0)