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
92285bed
Commit
92285bed
authored
May 27, 2015
by
miloyip
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add escape characters and control characters
parent
1784afe5
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
40 additions
and
1 deletion
+40
-1
regex.h
include/rapidjson/internal/regex.h
+32
-1
regextest.cpp
test/unittest/regextest.cpp
+8
-0
No files found.
include/rapidjson/internal/regex.h
View file @
92285bed
...
...
@@ -46,6 +46,12 @@ static const SizeType kRegexInvalidRange = ~SizeType(0);
- \c [a-z0-9_] Character class combination
- \c [^abc] Negated character classes
- \c [^a-c] Negated character class range
- \c \\| \\\\ ... Escape characters
- \c \\f Form feed (U+000C)
- \c \\n Line feed (U+000A)
- \c \\r Carriage return (U+000D)
- \c \\t Tab (U+0009)
- \c \\v Vertical tab (U+000B)
*/
template
<
typename
Encoding
,
typename
Allocator
=
CrtAllocator
>
class
GenericRegex
{
...
...
@@ -256,7 +262,32 @@ private:
ImplicitConcatenation
(
atomCountStack
,
operatorStack
);
break
;
default
:
case
'\\'
:
// Escape character
if
(
!
Encoding
::
Decode
(
is
,
&
codepoint
)
||
codepoint
==
0
)
return
;
// Expect an escape character
switch
(
codepoint
)
{
case
'|'
:
case
'('
:
case
')'
:
case
'?'
:
case
'*'
:
case
'+'
:
case
'.'
:
case
'['
:
case
']'
:
case
'\\'
:
break
;
// use the codepoint as is
case
'f'
:
codepoint
=
0x000C
;
break
;
case
'n'
:
codepoint
=
0x000A
;
break
;
case
'r'
:
codepoint
=
0x000D
;
break
;
case
't'
:
codepoint
=
0x0009
;
break
;
case
'v'
:
codepoint
=
0x000B
;
break
;
default
:
return
;
// Unsupported escape character
}
// fall through to default
default
:
// Pattern character
PushOperand
(
operandStack
,
codepoint
);
ImplicitConcatenation
(
atomCountStack
,
operatorStack
);
}
...
...
test/unittest/regextest.cpp
View file @
92285bed
...
...
@@ -327,4 +327,12 @@ TEST(Regex, CharacterRange8) {
EXPECT_FALSE
(
re
.
Match
(
"!"
));
}
TEST
(
Regex
,
Escape
)
{
const
char
*
s
=
"
\\
|
\\
(
\\
)
\\
?
\\
*
\\
+
\\
.
\\
[
\\
]
\\\\\\
f
\\
n
\\
r
\\
t
\\
v"
;
Regex
re
(
s
);
ASSERT_TRUE
(
re
.
IsValid
());
EXPECT_TRUE
(
re
.
Match
(
"|()?*+.[]
\\\x0C\n\r\t\x0B
"
));
EXPECT_FALSE
(
re
.
Match
(
s
));
// Not escaping
}
#undef EURO
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