RAPIDJSON_DIAG_OFF(padded)
25RAPIDJSON_DIAG_OFF(
switch-
enum)
26RAPIDJSON_DIAG_OFF(implicit-fallthrough)
31RAPIDJSON_DIAG_OFF(effc++)
36RAPIDJSON_DIAG_OFF(4512)
39 #ifndef RAPIDJSON_REGEX_VERBOSE 40 #define RAPIDJSON_REGEX_VERBOSE 0 49 template<
typenameSourceStream,
typenameEncoding>
53 unsigned Peek() {
returncodepoint_; }
55 unsignedc = codepoint_;
77 template<
typenameEncoding,
typenameAllocator>
112 template<
typenameEncoding,
typenameAllocator = CrtAllocator>
116 typedef typenameEncoding::Ch
Ch;
120states_(allocator, 256), ranges_(allocator, 256), root_(
kRegexInvalidState), stateCount_(), rangeCount_(),
121anchorBegin_(), anchorEnd_()
144 static const unsignedkAnyCharacterClass = 0xFFFFFFFF;
145 static const unsignedkRangeCharacterClass = 0xFFFFFFFE;
146 static const unsignedkRangeNegationFlag = 0x80000000;
170 returnstates_.template Bottom<State>()[index];
175 returnstates_.template Bottom<State>()[index];
180 returnranges_.template Bottom<Range>()[index];
185 returnranges_.template Bottom<Range>()[index];
188 template<
typenameInputStream>
195*atomCountStack.template Push<unsigned>() = 0;
198 while(ds.
Peek() != 0) {
199 switch(codepoint = ds.
Take()) {
201anchorBegin_ =
true;
209 while(!operatorStack.
Empty() && *operatorStack.template Top<Operator>() < kAlternation)
210 if(!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
212*operatorStack.template Push<Operator>() = kAlternation;
213*atomCountStack.template Top<unsigned>() = 0;
217*operatorStack.template Push<Operator>() = kLeftParenthesis;
218*atomCountStack.template Push<unsigned>() = 0;
222 while(!operatorStack.
Empty() && *operatorStack.template Top<Operator>() != kLeftParenthesis)
223 if(!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
225 if(operatorStack.
Empty())
227operatorStack.template Pop<Operator>(1);
228atomCountStack.template Pop<unsigned>(1);
229ImplicitConcatenation(atomCountStack, operatorStack);
233 if(!Eval(operandStack, kZeroOrOne))
238 if(!Eval(operandStack, kZeroOrMore))
243 if(!Eval(operandStack, kOneOrMore))
250 if(!ParseUnsigned(ds, &
n))
253 if(ds.
Peek() ==
',') {
255 if(ds.
Peek() ==
'}')
256m = kInfinityQuantifier;
257 else if(!ParseUnsigned(ds, &m) || m <
n)
263 if(!EvalQuantifier(operandStack,
n, m) || ds.
Peek() !=
'}')
270PushOperand(operandStack, kAnyCharacterClass);
271ImplicitConcatenation(atomCountStack, operatorStack);
277 if(!ParseRange(ds, &range))
280GetState(s).rangeStart = range;
281*operandStack.template Push<Frag>() =
Frag(s, s, s);
283ImplicitConcatenation(atomCountStack, operatorStack);
287 if(!CharacterEscape(ds, &codepoint))
292PushOperand(operandStack, codepoint);
293ImplicitConcatenation(atomCountStack, operatorStack);
297 while(!operatorStack.
Empty())
298 if(!Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
303 Frag* e = operandStack.template Pop<Frag>(1);
307 #if RAPIDJSON_REGEX_VERBOSE 308printf(
"root: %d\n", root_);
310 State& s = GetState(
i);
311printf(
"[%2d] out: %2d out1: %2d c: '%c'\n",
i, s.
out, s.
out1, (
char)s.
codepoint);
319 State* s = states_.template Push<State>();
324 returnstateCount_++;
329*operandStack.template Push<Frag>() =
Frag(s, s, s);
333 if(*atomCountStack.template Top<unsigned>())
334*operatorStack.template Push<Operator>() = kConcatenation;
335(*atomCountStack.template Top<unsigned>())++;
341l1 = GetState(l1).out;
342GetState(l1).out = l2;
348 next= GetState(
l).out;
349GetState(
l).out = s;
358 Frage2 = *operandStack.template Pop<Frag>(1);
359 Frage1 = *operandStack.template Pop<Frag>(1);
366 if(operandStack.
GetSize() >=
sizeof(
Frag) * 2) {
367 Frage2 = *operandStack.template Pop<Frag>(1);
368 Frage1 = *operandStack.template Pop<Frag>(1);
377 Frage = *operandStack.template Pop<Frag>(1);
379*operandStack.template Push<Frag>() =
Frag(s, Append(e.
out, s), e.
minIndex);
386 Frage = *operandStack.template Pop<Frag>(1);
389*operandStack.template Push<Frag>() =
Frag(s, s, e.
minIndex);
397 Frage = *operandStack.template Pop<Frag>(1);
414 else if(m == kInfinityQuantifier)
415Eval(operandStack, kZeroOrMore);
417Eval(operandStack, kZeroOrOne);
418 for(
unsigned i= 0;
i< m - 1;
i++)
419CloneTopOperand(operandStack);
420 for(
unsigned i= 0;
i< m - 1;
i++)
421Eval(operandStack, kConcatenation);
426 for(
unsigned i= 0;
i<
n- 1;
i++)
427CloneTopOperand(operandStack);
429 if(m == kInfinityQuantifier)
430Eval(operandStack, kOneOrMore);
432CloneTopOperand(operandStack);
433Eval(operandStack, kZeroOrOne);
434 for(
unsigned i=
n;
i< m - 1;
i++)
435CloneTopOperand(operandStack);
436 for(
unsigned i=
n;
i< m;
i++)
437Eval(operandStack, kConcatenation);
440 for(
unsigned i= 0;
i<
n- 1;
i++)
441Eval(operandStack, kConcatenation);
449 const Fragsrc = *operandStack.template Top<Frag>();
451 State* s = states_.template Push<State>(
count);
460stateCount_ +=
count;
463 template<
typenameInputStream>
466 if(ds.
Peek() <
'0'|| ds.
Peek() >
'9')
468 while(ds.
Peek() >=
'0'&& ds.
Peek() <=
'9') {
469 if(
r>= 429496729 && ds.
Peek() >
'5')
471 r=
r* 10 + (ds.
Take() -
'0');
477 template<
typenameInputStream>
479 boolisBegin =
true;
480 boolnegate =
false;
485 while((codepoint = ds.
Take()) != 0) {
488 if(codepoint ==
'^') {
501GetRange(current).next =
r;
504GetRange(start).start |= kRangeNegationFlag;
509 if(ds.
Peek() ==
'b') {
513 else if(!CharacterEscape(ds, &codepoint))
520 if(codepoint ==
'-') {
530GetRange(current).next =
r;
540GetRange(current).end = codepoint;
549 Range*
r= ranges_.template Push<Range>();
550 r->start =
r->end = codepoint;
552 returnrangeCount_++;
555 template<
typenameInputStream>
558 switch(codepoint = ds.
Take()) {
573*escapedCodepoint = codepoint;
return true;
574 case 'f': *escapedCodepoint = 0x000C;
return true;
575 case 'n': *escapedCodepoint = 0x000A;
return true;
576 case 'r': *escapedCodepoint = 0x000D;
return true;
577 case 't': *escapedCodepoint = 0x0009;
return true;
578 case 'v': *escapedCodepoint = 0x000B;
return true;
590 static const unsignedkInfinityQuantifier = ~0u;
597 template<
typenameRegexType,
typenameAllocator = CrtAllocator>
600 typedef typenameRegexType::EncodingType
Encoding;
601 typedef typenameEncoding::Ch
Ch;
604regex_(regex), allocator_(allocator), ownAllocator_(0),
605state0_(allocator, 0), state1_(allocator, 0), stateSet_()
610stateSet_ =
static_cast<unsigned*
>(allocator_->Malloc(GetStateSetSize()));
611state0_.template Reserve<SizeType>(regex_.stateCount_);
612state1_.template Reserve<SizeType>(regex_.stateCount_);
620 template<
typenameInputStream>
622 returnSearchWithAnchoring(is,
true,
true);
630 template<
typenameInputStream>
632 returnSearchWithAnchoring(is, regex_.anchorBegin_, regex_.anchorEnd_);
641 typedef typenameRegexType::State
State;
642 typedef typenameRegexType::Range
Range;
644 template<
typenameInputStream>
650 const size_tstateSetSize = GetStateSetSize();
651std::memset(stateSet_, 0, stateSetSize);
653 boolmatched = AddState(*current, regex_.root_);
655 while(!current->
Empty() && (codepoint = ds.
Take()) != 0) {
656std::memset(stateSet_, 0, stateSetSize);
659 for(
const SizeType* s = current->template Bottom<SizeType>(); s != current->template End<SizeType>(); ++s) {
660 const State& sr = regex_.GetState(*s);
661 if(sr.codepoint == codepoint ||
662sr.codepoint == RegexType::kAnyCharacterClass ||
663(sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint)))
665matched = AddState(*
next, sr.out) || matched;
666 if(!anchorEnd && matched)
670AddState(*
next, regex_.root_);
679 return(regex_.stateCount_ + 31) / 32 * 4;
686 const State& s = regex_.GetState(index);
688 boolmatched = AddState(
l, s.out);
689 returnAddState(
l, s.out1) || matched;
691 else if(!(stateSet_[index >> 5] & (1u << (index & 31)))) {
692stateSet_[index >> 5] |= (1u << (index & 31));
693*
l.template PushUnsafe<SizeType>() = index;
699 bool yes= (regex_.GetRange(rangeIndex).start & RegexType::kRangeNegationFlag) == 0;
701 const Range&
r= regex_.GetRange(rangeIndex);
702 if(codepoint >= (
r.start & ~RegexType::kRangeNegationFlag) && codepoint <=
r.end)
704rangeIndex =
r.next;
Concept for allocating, resizing and freeing memory block.
Concept for encoding of Unicode characters.
DecodedStream(SourceStream &ss)
Stack< Allocator > state1_
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd)
size_t GetStateSetSize() const
bool Search(InputStream &is)
RegexType::EncodingType Encoding
Allocator * ownAllocator_
bool AddState(Stack< Allocator > &l, SizeType index)
bool Match(InputStream &is)
GenericRegexSearch(const RegexType ®ex, Allocator *allocator=0)
Stack< Allocator > state0_
bool MatchRange(SizeType rangeIndex, unsigned codepoint) const
Regular expression engine with subset of ECMAscript grammar.
bool ParseRange(DecodedStream< InputStream, Encoding > &ds, SizeType *range)
static SizeType Min(SizeType a, SizeType b)
void PushOperand(Stack< Allocator > &operandStack, unsigned codepoint)
void CloneTopOperand(Stack< Allocator > &operandStack)
void ImplicitConcatenation(Stack< Allocator > &atomCountStack, Stack< Allocator > &operatorStack)
bool CharacterEscape(DecodedStream< InputStream, Encoding > &ds, unsigned *escapedCodepoint)
bool Eval(Stack< Allocator > &operandStack, Operator op)
Range & GetRange(SizeType index)
SizeType NewState(SizeType out, SizeType out1, unsigned codepoint)
SizeType NewRange(unsigned codepoint)
const Range & GetRange(SizeType index) const
void Parse(DecodedStream< InputStream, Encoding > &ds)
State & GetState(SizeType index)
Stack< Allocator > states_
void Patch(SizeType l, SizeType s)
bool EvalQuantifier(Stack< Allocator > &operandStack, unsigned n, unsigned m)
const State & GetState(SizeType index) const
bool ParseUnsigned(DecodedStream< InputStream, Encoding > &ds, unsigned *u)
Stack< Allocator > ranges_
SizeType Append(SizeType l1, SizeType l2)
GenericRegex(const Ch *source, Allocator *allocator=0)
A type-unsafe stack for storing different types of data.
std::ofstream out("events_result.xml")
main entry point for tests
static DLIST_TYPE *DLIST_NAME() next(DLIST_LIST_TYPE *list, DLIST_TYPE *item)
#define RAPIDJSON_ASSERT(x)
Assertion.
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
fallback to Cassandra storage</td > n</tr > n</table > n</td > n< td > yes
static const SizeType kRegexInvalidState
Represents an invalid index in GenericRegex::State::out, out1.
static const SizeType kRegexInvalidRange
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
GenericRegex< UTF8<> > Regex
GenericRegexSearch< Regex > RegexSearch
const CharType(& source)[N]
unsigned SizeType
Size type (for string lengths, array sizes, etc.)
double r(size_t dimension_, const Int4 *score_, const double *prob_, double theta_)
#define RAPIDJSON_DELETE(x)
! customization point for global delete
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
static SLJIT_INLINE sljit_ins l(sljit_gpr r, sljit_s32 d, sljit_gpr x, sljit_gpr b)
Frag(SizeType s, SizeType o, SizeType m)
SizeType out
link-list of all output states
SizeType out
Equals to kInvalid for matching state.
SizeType out1
Equals to non-kInvalid for split.
void Decode(const vector< char > &, CRawScoreVector< Key, Score > &)
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4