11/*
22 * Regex.h
33 *
4- * Created on: Nov 27, 2011
4+ * Created on: Nov 27, 2014
55 * Author: leonid.gorelik
66 */
77
88#ifndef REGEX_H_
99#define REGEX_H_
1010
1111#include < iostream>
12- #include < string>
1312#include " sys/time.h"
14- // Define RE2 regular expression engine
1513#include " re2/re2.h"
16- // Define SPL types and functions.
14+
1715#include " SPL/Runtime/Function/SPLFunctions.h"
1816
1917using namespace std ;
@@ -41,14 +39,14 @@ namespace regex {
4139 }
4240
4341 template <typename Index, typename OP>
44- inline RE2& getRE2 (const string & pattern=" " , int maxmem=1000000 ){
45- static RE2 regex (pattern, getRE2Options<Index,OP>(maxmem));
42+ inline RE2& getRE2 (const SPL::rstring & pattern=" " , int maxmem=1000000 ){
43+ static RE2 regex (re2::StringPiece ( pattern. data (), pattern. size ()) , getRE2Options<Index,OP>(maxmem));
4644 return regex;
4745 }
4846
4947 template <typename Index>
50- inline RE2& getRE2Static (const string & pattern=" " , int maxmem=1000000 ){
51- static RE2 regex (pattern, getRE2OptionsStatic<Index>(maxmem));
48+ inline RE2& getRE2Static (const SPL::rstring & pattern=" " , int maxmem=1000000 ){
49+ static RE2 regex (re2::StringPiece ( pattern. data (), pattern. size ()) , getRE2OptionsStatic<Index>(maxmem));
5250 return regex;
5351 }
5452
@@ -62,32 +60,32 @@ namespace regex {
6260 getRE2Static<Index>(pattern, maxmem);
6361 }
6462
65- inline bool regexFullMatch (const string & str, const SPL::rstring & pattern){
66- return RE2::FullMatch (str, pattern) == 1 ;
63+ inline bool regexFullMatch (const SPL::rstring & str, const SPL::rstring & pattern){
64+ return RE2::FullMatch (re2::StringPiece ( str. data (), str. size ()), re2::StringPiece ( pattern. data (), pattern. size ()) ) == 1 ;
6765 }
6866
6967 template <typename Index>
70- inline bool regexFullMatch (const string & str, const Index & patternIndex){
71- return RE2::FullMatch (str, getRE2<Index,OperatorInstance>()) == 1 ;
68+ inline bool regexFullMatch (const SPL::rstring & str, const Index & patternIndex){
69+ return RE2::FullMatch (re2::StringPiece ( str. data (), str. size ()) , getRE2<Index,OperatorInstance>()) == 1 ;
7270 }
7371
7472 template <typename Index>
75- inline bool regexFullMatchStatic (const string & str, const Index & patternIndex){
76- return RE2::FullMatch (str, getRE2Static<Index>()) == 1 ;
73+ inline bool regexFullMatchStatic (const SPL::rstring & str, const Index & patternIndex){
74+ return RE2::FullMatch (re2::StringPiece ( str. data (), str. size ()) , getRE2Static<Index>()) == 1 ;
7775 }
7876
79- inline bool regexPartialMatch (const string & str, const SPL::rstring & pattern){
80- return RE2::PartialMatch (str, pattern) == 1 ;
77+ inline bool regexPartialMatch (const SPL::rstring & str, const SPL::rstring & pattern){
78+ return RE2::PartialMatch (re2::StringPiece ( str. data (), str. size ()), re2::StringPiece ( pattern. data (), pattern. size ()) ) == 1 ;
8179 }
8280
8381 template <typename Index>
84- inline bool regexPartialMatch (const string & str, const Index & patternIndex){
85- return RE2::PartialMatch (str, getRE2<Index,OperatorInstance>()) == 1 ;
82+ inline bool regexPartialMatch (const SPL::rstring & str, const Index & patternIndex){
83+ return RE2::PartialMatch (re2::StringPiece ( str. data (), str. size ()) , getRE2<Index,OperatorInstance>()) == 1 ;
8684 }
8785
8886 template <typename Index>
89- inline bool regexPartialMatchStatic (const string & str, const Index & patternIndex){
90- return RE2::PartialMatch (str, getRE2Static<Index>()) == 1 ;
87+ inline bool regexPartialMatchStatic (const SPL::rstring & str, const Index & patternIndex){
88+ return RE2::PartialMatch (re2::StringPiece ( str. data (), str. size ()) , getRE2Static<Index>()) == 1 ;
9189 }
9290}
9391
0 commit comments