@@ -118,15 +118,19 @@ class GenericRegex {
118
118
template <typename , typename > friend class GenericRegexSearch ;
119
119
120
120
GenericRegex (const Ch* source, Allocator* allocator = 0 ) :
121
- states_ (allocator, 256 ), ranges_(allocator, 256 ), root_(kRegexInvalidState ), stateCount_(), rangeCount_(),
121
+ ownAllocator_ (allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_),
122
+ states_ (allocator_, 256 ), ranges_(allocator_, 256 ), root_(kRegexInvalidState ), stateCount_(), rangeCount_(),
122
123
anchorBegin_ (), anchorEnd_()
123
124
{
124
125
GenericStringStream<Encoding> ss (source);
125
126
DecodedStream<GenericStringStream<Encoding>, Encoding> ds (ss);
126
127
Parse (ds);
127
128
}
128
129
129
- ~GenericRegex () {}
130
+ ~GenericRegex ()
131
+ {
132
+ RAPIDJSON_DELETE (ownAllocator_);
133
+ }
130
134
131
135
bool IsValid () const {
132
136
return root_ != kRegexInvalidState ;
@@ -188,10 +192,9 @@ class GenericRegex {
188
192
189
193
template <typename InputStream>
190
194
void Parse (DecodedStream<InputStream, Encoding>& ds) {
191
- Allocator allocator;
192
- Stack<Allocator> operandStack (&allocator, 256 ); // Frag
193
- Stack<Allocator> operatorStack (&allocator, 256 ); // Operator
194
- Stack<Allocator> atomCountStack (&allocator, 256 ); // unsigned (Atom per parenthesis)
195
+ Stack<Allocator> operandStack (allocator_, 256 ); // Frag
196
+ Stack<Allocator> operatorStack (allocator_, 256 ); // Operator
197
+ Stack<Allocator> atomCountStack (allocator_, 256 ); // unsigned (Atom per parenthesis)
195
198
196
199
*atomCountStack.template Push <unsigned >() = 0 ;
197
200
@@ -582,6 +585,8 @@ class GenericRegex {
582
585
}
583
586
}
584
587
588
+ Allocator* ownAllocator_;
589
+ Allocator* allocator_;
585
590
Stack<Allocator> states_;
586
591
Stack<Allocator> ranges_;
587
592
SizeType root_;
0 commit comments