15 #ifndef RAPIDJSON_INTERNAL_REGEX_H_ 16 #define RAPIDJSON_INTERNAL_REGEX_H_ 18 #include "../allocators.h" 19 #include "../stream.h" 24 RAPIDJSON_DIAG_OFF(padded)
25 RAPIDJSON_DIAG_OFF(
switch-
enum)
26 RAPIDJSON_DIAG_OFF(implicit-fallthrough)
31 RAPIDJSON_DIAG_OFF(effc++)
36 RAPIDJSON_DIAG_OFF(4512)
39 #ifndef RAPIDJSON_REGEX_VERBOSE 40 #define RAPIDJSON_REGEX_VERBOSE 0 84 template <
typename Encoding,
typename Allocator = CrtAllocator>
87 typedef typename Encoding::Ch
Ch;
106 template <
typename InputStream>
116 template <
typename InputStream>
160 template <
typename SourceStream>
202 template <
typename InputStream>
209 *atomCountStack.template Push<unsigned>() = 0;
212 while (ds.
Peek() != 0) {
223 while (!operatorStack.
Empty() && *operatorStack.template Top<Operator>() <
kAlternation)
224 if (!
Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
226 *operatorStack.template Push<Operator>() =
kAlternation;
227 *atomCountStack.template Top<unsigned>() = 0;
232 *atomCountStack.template Push<unsigned>() = 0;
237 if (!
Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
239 if (operatorStack.
Empty())
241 operatorStack.template Pop<Operator>(1);
242 atomCountStack.template Pop<unsigned>(1);
267 if (ds.
Peek() ==
',') {
269 if (ds.
Peek() ==
'}')
295 *operandStack.template Push<Frag>() =
Frag(
s,
s,
s);
311 while (!operatorStack.
Empty())
312 if (!
Eval(operandStack, *operatorStack.template Pop<Operator>(1)))
317 Frag* e = operandStack.template Pop<Frag>(1);
321 #if RAPIDJSON_REGEX_VERBOSE 322 printf(
"root: %d\n",
root_);
325 printf(
"[%2d] out: %2d out1: %2d c: '%c'\n", i,
s.out,
s.out1, (
char)
s.codepoint);
351 *operandStack.template Push<Frag>() =
Frag(
s,
s,
s);
355 if (*atomCountStack.template Top<unsigned>())
357 (*atomCountStack.template Top<unsigned>())++;
380 Frag e2 = *operandStack.template Pop<Frag>(1);
381 Frag e1 = *operandStack.template Pop<Frag>(1);
382 Patch(e1.out, e2.start);
383 *operandStack.template Push<Frag>() =
Frag(e1.start, e2.out,
Min(e1.minIndex, e2.minIndex));
389 Frag e2 = *operandStack.template Pop<Frag>(1);
390 Frag e1 = *operandStack.template Pop<Frag>(1);
392 *operandStack.template Push<Frag>() =
Frag(
s,
Append(e1.out, e2.out),
Min(e1.minIndex, e2.minIndex));
399 Frag e = *operandStack.template Pop<Frag>(1);
408 Frag e = *operandStack.template Pop<Frag>(1);
419 Frag e = *operandStack.template Pop<Frag>(1);
440 for (
unsigned i = 0; i <
m - 1; i++)
442 for (
unsigned i = 0; i <
m - 1; i++)
448 for (
unsigned i = 0; i <
n - 1; i++)
456 for (
unsigned i =
n; i <
m - 1; i++)
458 for (
unsigned i =
n; i <
m; i++)
462 for (
unsigned i = 0; i <
n - 1; i++)
471 const Frag src = *operandStack.template Top<Frag>();
485 template <
typename InputStream>
488 if (ds.
Peek() <
'0' || ds.
Peek() >
'9')
490 while (ds.
Peek() >=
'0' && ds.
Peek() <=
'9') {
491 if (
r >= 429496729 && ds.
Peek() >
'5')
493 r =
r * 10 + (ds.
Take() -
'0');
499 template <
typename InputStream>
531 if (ds.
Peek() ==
'b') {
577 template <
typename InputStream>
595 *escapedCodepoint =
codepoint;
return true;
596 case 'f': *escapedCodepoint = 0x000C;
return true;
597 case 'n': *escapedCodepoint = 0x000A;
return true;
598 case 'r': *escapedCodepoint = 0x000D;
return true;
599 case 't': *escapedCodepoint = 0x0009;
return true;
600 case 'v': *escapedCodepoint = 0x000B;
return true;
606 template <
typename InputStream>
622 for (
const SizeType*
s = current->template Bottom<SizeType>();
s != current->template End<SizeType>(); ++
s) {
629 if (!anchorEnd && matched)
656 *
l.template PushUnsafe<SizeType>() =
index;
701 #endif // RAPIDJSON_INTERNAL_REGEX_H_ SizeType rangeStart
Definition: regex.h:149
unsigned Take()
Definition: regex.h:165
const Range & GetRange(SizeType index) const
Definition: regex.h:197
GenericRegex< UTF8<> > Regex
Definition: regex.h:688
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
A type-unsafe stack for storing different types of data.
Definition: stack.h:36
set set set set set set set macro pixldst1 op
Definition: pixman-arm-neon-asm.h:54
bool SearchWithAnchoring(InputStream &is, bool anchorBegin, bool anchorEnd) const
Definition: regex.h:607
const State & GetState(SizeType index) const
Definition: regex.h:187
Stack< Allocator > state0_
Definition: regex.h:682
static int codepoint(lua_State *L)
Definition: lutf8lib.c:100
bool Match(const Ch *s) const
Definition: regex.h:111
State & GetState(SizeType index)
Definition: regex.h:182
GLuint start
Definition: glext.h:6292
SizeType out
Equals to kInvalid for matching state.
Definition: regex.h:147
Stack< Allocator > states_
Definition: regex.h:672
GLdouble GLdouble GLdouble r
Definition: glext.h:6406
SizeType NewRange(unsigned codepoint)
Definition: regex.h:570
Frag(SizeType s, SizeType o, SizeType m)
Definition: regex.h:154
bool IsValid() const
Definition: regex.h:102
GLenum GLint * range
Definition: glext.h:8206
size_t GetSize() const
Definition: stack.h:176
bool MatchRange(SizeType rangeIndex, unsigned codepoint) const
Definition: regex.h:661
bf_uint8_t l2
Definition: connect_ps4.c:75
void Patch(SizeType l, SizeType s)
Definition: regex.h:368
#define next(ls)
Definition: llex.c:32
GLdouble s
Definition: glext.h:6390
struct passwd out
Definition: missing_libc_functions.c:51
bool CharacterEscape(DecodedStream< InputStream > &ds, unsigned *escapedCodepoint)
Definition: regex.h:578
bool Eval(Stack< Allocator > &operandStack, Operator op)
Definition: regex.h:375
unsigned codepoint
Definition: regex.h:150
void PushOperand(Stack< Allocator > &operandStack, unsigned codepoint)
Definition: regex.h:349
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:119
Read-only string stream.
Definition: fwd.h:47
const GLubyte * c
Definition: glext.h:9812
GLboolean GLboolean GLboolean b
Definition: glext.h:6844
static const unsigned kAnyCharacterClass
For '.'.
Definition: regex.h:136
uint32_t * stateSet_
Definition: regex.h:681
GLuint GLuint GLsizei count
Definition: glext.h:6292
SizeType stateCount_
Definition: regex.h:675
SizeType rangeCount_
Definition: regex.h:676
SizeType minIndex
Definition: regex.h:157
static SizeType Min(SizeType a, SizeType b)
Definition: regex.h:468
bf_uint8_t l1
Definition: connect_ps4.c:73
static const unsigned kInfinityQuantifier
Definition: regex.h:678
bool Search(InputStream &is) const
Definition: regex.h:117
bool l
Definition: connect_wiiupro.c:37
bool ParseRange(DecodedStream< InputStream > &ds, SizeType *range)
Definition: regex.h:500
SizeType NewState(SizeType out, SizeType out1, unsigned codepoint)
Definition: regex.h:340
SizeType next
Definition: regex.h:143
Range & GetRange(SizeType index)
Definition: regex.h:192
SizeType start
Definition: regex.h:155
Stack< Allocator > ranges_
Definition: regex.h:673
bool anchorEnd_
Definition: regex.h:685
static const unsigned kRangeNegationFlag
Definition: regex.h:138
Encoding::Ch Ch
Definition: regex.h:87
SizeType out
link-list of all output states
Definition: regex.h:156
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:402
GLenum src
Definition: glext.h:6980
void Parse(DecodedStream< InputStream > &ds)
Definition: regex.h:203
static const unsigned kRangeCharacterClass
Definition: regex.h:137
SizeType Append(SizeType l1, SizeType l2)
Definition: regex.h:360
Definition: document.h:391
bool Empty() const
Definition: stack.h:175
static const SizeType kRegexInvalidState
Represents an invalid index in GenericRegex::State::out, out1.
Definition: regex.h:49
unsigned end
Definition: regex.h:142
unsigned start
Definition: regex.h:141
SizeType out1
Equals to non-kInvalid for split.
Definition: regex.h:148
GLuint index
Definition: glext.h:6671
bool Match(InputStream &is) const
Definition: regex.h:107
GLsizei GLsizei GLchar * source
Definition: glext.h:6688
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:116
size_t GetStateSetSize() const
Definition: regex.h:641
GLint j
Definition: nx_glsym.h:307
unsigned codepoint_
Definition: regex.h:179
SizeType root_
Definition: regex.h:674
Stack< Allocator > state1_
Definition: regex.h:683
DecodedStream(SourceStream &ss)
Definition: regex.h:163
void Decode()
Definition: regex.h:173
GenericRegex(const Ch *source, Allocator *allocator=0)
Definition: regex.h:89
unsigned Peek()
Definition: regex.h:164
void CloneTopOperand(Stack< Allocator > &operandStack)
Definition: regex.h:470
bool AddState(Stack< Allocator > &l, SizeType index) const
Definition: regex.h:646
Operator
Definition: regex.h:127
bool ParseUnsigned(DecodedStream< InputStream > &ds, unsigned *u)
Definition: regex.h:486
bool anchorBegin_
Definition: regex.h:684
static const SizeType kRegexInvalidRange
Definition: regex.h:50
void * memset(void *b, int c, size_t len)
Definition: string.c:7
bool EvalQuantifier(Stack< Allocator > &operandStack, unsigned n, unsigned m)
Definition: regex.h:429
SourceStream & ss_
Definition: regex.h:178
GLdouble n
Definition: glext.h:8396
unsigned int uint32_t
Definition: stdint.h:126
const GLfloat * m
Definition: glext.h:11755
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6844
Regular expression engine with subset of ECMAscript grammar.
Definition: regex.h:85
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:380
bool Search(const Ch *s) const
Definition: regex.h:121
void * memcpy(void *dst, const void *src, size_t len)
Definition: string.c:26
void ImplicitConcatenation(Stack< Allocator > &atomCountStack, Stack< Allocator > &operatorStack)
Definition: regex.h:354
~GenericRegex()
Definition: regex.h:98