Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
gaoqiong
yaml-cpp
Commits
e3ff87ec
Commit
e3ff87ec
authored
Sep 07, 2009
by
Jesse Beder
Browse files
Fixed bugs in escape characters (both parsing and emitting)
parent
45ac700f
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
46 additions
and
4 deletions
+46
-4
src/emitterutils.cpp
src/emitterutils.cpp
+1
-1
src/exp.cpp
src/exp.cpp
+4
-3
yaml-reader/spectests.cpp
yaml-reader/spectests.cpp
+41
-0
No files found.
src/emitterutils.cpp
View file @
e3ff87ec
...
...
@@ -83,7 +83,7 @@ namespace YAML
}
else
{
// TODO: for the common escaped characters, give their usual symbol
std
::
stringstream
str
;
str
<<
"
\\
x"
<<
std
::
hex
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
static_cast
<
int
>
(
ch
);
str
<<
"
\\
x"
<<
std
::
hex
<<
std
::
setfill
(
'0'
)
<<
std
::
setw
(
2
)
<<
static_cast
<
unsigned
int
>
(
static_cast
<
unsigned
char
>
(
ch
)
);
out
<<
str
.
str
();
}
}
...
...
src/exp.cpp
View file @
e3ff87ec
...
...
@@ -83,7 +83,7 @@ namespace YAML
// now do the slash (we're not gonna check if it's a slash - you better pass one!)
switch
(
ch
)
{
case
'0'
:
return
"
\0
"
;
case
'0'
:
return
std
::
string
(
"
\x00
"
,
1
)
;
case
'a'
:
return
"
\x07
"
;
case
'b'
:
return
"
\x08
"
;
case
't'
:
...
...
@@ -97,8 +97,9 @@ namespace YAML
case
'\"'
:
return
"
\"
"
;
case
'\''
:
return
"
\'
"
;
case
'\\'
:
return
"
\\
"
;
case
'N'
:
return
"
\xC2\x85
"
;
// NEL (#x85)
case
'_'
:
return
"
\xC2\xA0
"
;
// #xA0
case
'/'
:
return
"/"
;
case
'N'
:
return
"
\x85
"
;
case
'_'
:
return
"
\xA0
"
;
case
'L'
:
return
"
\xE2\x80\xA8
"
;
// LS (#x2028)
case
'P'
:
return
"
\xE2\x80\xA9
"
;
// PS (#x2029)
case
'x'
:
return
Escape
(
in
,
2
);
...
...
yaml-reader/spectests.cpp
View file @
e3ff87ec
...
...
@@ -793,6 +793,45 @@ namespace Test {
"}"
);
return
true
;
}
// 5.13
TEST
EscapedCharacters
()
{
std
::
string
input
=
"
\"
Fun with
\\\\\n
"
"
\\\"
\\
a
\\
b
\\
e
\\
f
\\\n
"
"
\\
n
\\
r
\\
t
\\
v
\\
0
\\\n
"
"
\\
\\
_
\\
N
\\
L
\\
P
\\\n
"
"
\\
x41
\\
u0041
\\
U00000041
\"
"
;
std
::
stringstream
stream
(
input
);
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
YAML_ASSERT
(
doc
==
"Fun with
\x5C
\x22
\x07
\x08
\x1B
\x0C
\x0A
\x0D
\x09
\x0B
"
+
std
::
string
(
"
\x00
"
,
1
)
+
"
\x20
\xA0
\x85
\u2028 \u2029 A A A"
);
return
true
;
}
// 5.14
TEST
InvalidEscapedCharacters
()
{
std
::
string
input
=
"Bad escapes:
\n
"
"
\"\\
c
\n
"
"
\\
xq-
\"
"
;
std
::
stringstream
stream
(
input
);
try
{
YAML
::
Parser
parser
(
stream
);
YAML
::
Node
doc
;
parser
.
GetNextDocument
(
doc
);
}
catch
(
const
YAML
::
ParserException
&
e
)
{
YAML_ASSERT
(
e
.
msg
==
YAML
::
ErrorMsg
::
INVALID_ESCAPE
+
"c"
);
return
true
;
}
return
false
;
}
}
bool
RunSpecTests
()
...
...
@@ -827,6 +866,8 @@ namespace Test {
RunSpecTest
(
&
Spec
::
QuotedScalarIndicators
,
"5.8"
,
"Quoted Scalar Indicators"
,
passed
);
RunSpecTest
(
&
Spec
::
LineBreakCharacters
,
"5.11"
,
"Line Break Characters"
,
passed
);
RunSpecTest
(
&
Spec
::
TabsAndSpaces
,
"5.12"
,
"Tabs and Spaces"
,
passed
);
RunSpecTest
(
&
Spec
::
EscapedCharacters
,
"5.13"
,
"Escaped Characters"
,
passed
);
RunSpecTest
(
&
Spec
::
InvalidEscapedCharacters
,
"5.14"
,
"Invalid Escaped Characters"
,
passed
);
return
passed
;
}
...
...
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