Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
R
rapidjson
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
rapidjson
Commits
ecd8fa34
Commit
ecd8fa34
authored
Apr 16, 2016
by
Milo Yip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Improve coverage of regex
parent
c71825f8
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
16 additions
and
7 deletions
+16
-7
regex.h
include/rapidjson/internal/regex.h
+5
-7
regextest.cpp
test/unittest/regextest.cpp
+11
-0
No files found.
include/rapidjson/internal/regex.h
View file @
ecd8fa34
...
...
@@ -375,14 +375,14 @@ private:
bool
Eval
(
Stack
<
Allocator
>&
operandStack
,
Operator
op
)
{
switch
(
op
)
{
case
kConcatenation
:
if
(
operandStack
.
GetSize
()
>=
sizeof
(
Frag
)
*
2
)
{
RAPIDJSON_ASSERT
(
operandStack
.
GetSize
()
>=
sizeof
(
Frag
)
*
2
);
{
Frag
e2
=
*
operandStack
.
template
Pop
<
Frag
>
(
1
);
Frag
e1
=
*
operandStack
.
template
Pop
<
Frag
>
(
1
);
Patch
(
e1
.
out
,
e2
.
start
);
*
operandStack
.
template
Push
<
Frag
>
()
=
Frag
(
e1
.
start
,
e2
.
out
,
Min
(
e1
.
minIndex
,
e2
.
minIndex
));
return
true
;
}
return
fals
e
;
return
tru
e
;
case
kAlternation
:
if
(
operandStack
.
GetSize
()
>=
sizeof
(
Frag
)
*
2
)
{
...
...
@@ -430,8 +430,7 @@ private:
bool
EvalQuantifier
(
Stack
<
Allocator
>&
operandStack
,
unsigned
n
,
unsigned
m
)
{
RAPIDJSON_ASSERT
(
n
<=
m
);
if
(
operandStack
.
GetSize
()
<
sizeof
(
Frag
))
return
false
;
RAPIDJSON_ASSERT
(
operandStack
.
GetSize
()
>=
sizeof
(
Frag
));
if
(
n
==
0
)
{
if
(
m
==
0
)
// a{0} not support
...
...
@@ -647,8 +646,7 @@ private:
// Return whether the added states is a match state
bool
AddState
(
Stack
<
Allocator
>&
l
,
SizeType
index
)
const
{
if
(
index
==
kRegexInvalidState
)
return
true
;
RAPIDJSON_ASSERT
(
index
!=
kRegexInvalidState
);
const
State
&
s
=
GetState
(
index
);
if
(
s
.
out1
!=
kRegexInvalidState
)
{
// Split
...
...
test/unittest/regextest.cpp
View file @
ecd8fa34
...
...
@@ -17,6 +17,14 @@
using
namespace
rapidjson
::
internal
;
TEST
(
Regex
,
Single
)
{
Regex
re
(
"a"
);
ASSERT_TRUE
(
re
.
IsValid
());
EXPECT_TRUE
(
re
.
Match
(
"a"
));
EXPECT_FALSE
(
re
.
Match
(
""
));
EXPECT_FALSE
(
re
.
Match
(
"b"
));
}
TEST
(
Regex
,
Concatenation
)
{
Regex
re
(
"abc"
);
ASSERT_TRUE
(
re
.
IsValid
());
...
...
@@ -560,6 +568,9 @@ TEST(Regex, Invalid) {
TEST_INVALID
(
"a{1,0}"
);
TEST_INVALID
(
"a{-1,0}"
);
TEST_INVALID
(
"a{-1,1}"
);
TEST_INVALID
(
"a{4294967296}"
);
// overflow of unsigned
TEST_INVALID
(
"a{1a}"
);
TEST_INVALID
(
"["
);
TEST_INVALID
(
"[]"
);
TEST_INVALID
(
"[^]"
);
TEST_INVALID
(
"[
\\
a]"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment