Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yaml-cpp
Overview
Overview
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
yaml-cpp
Commits
ee9c4d19
Commit
ee9c4d19
authored
Aug 22, 2024
by
Simon Gene Gottlieb
Committed by
Jesse Beder
Aug 22, 2024
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: parse files with '\r' symbols as line ending correctly
parent
b38ac5b5
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
1 deletions
+35
-1
src/stream.cpp
+18
-1
src/stream.h
+1
-0
test/integration/load_node_test.cpp
+16
-0
No files found.
src/stream.cpp
View file @
ee9c4d19
...
...
@@ -262,7 +262,24 @@ char Stream::get() {
AdvanceCurrent
();
m_mark
.
column
++
;
if
(
ch
==
'\n'
)
{
// if line ending symbol is unknown, set it to the first
// encountered line ending.
// if line ending '\r' set ending symbol to '\r'
// other wise set it to '\n'
if
(
!
m_lineEndingSymbol
)
{
if
(
ch
==
'\n'
)
{
// line ending is '\n'
m_lineEndingSymbol
=
'\n'
;
}
else
if
(
ch
==
'\r'
)
{
auto
ch2
=
peek
();
if
(
ch2
==
'\n'
)
{
// line ending is '\r\n'
m_lineEndingSymbol
=
'\n'
;
}
else
{
// line ending is '\r'
m_lineEndingSymbol
=
'\r'
;
}
}
}
if
(
ch
==
m_lineEndingSymbol
)
{
m_mark
.
column
=
0
;
m_mark
.
line
++
;
}
...
...
src/stream.h
View file @
ee9c4d19
...
...
@@ -53,6 +53,7 @@ class Stream {
Mark
m_mark
;
CharacterSet
m_charSet
;
char
m_lineEndingSymbol
{};
// 0 means it is not determined yet, must be '\n' or '\r'
mutable
std
::
deque
<
char
>
m_readahead
;
unsigned
char
*
const
m_pPrefetched
;
mutable
size_t
m_nPrefetchedAvailable
;
...
...
test/integration/load_node_test.cpp
View file @
ee9c4d19
...
...
@@ -360,5 +360,21 @@ TEST(LoadNodeTest, BlockCRNLEncoded) {
EXPECT_EQ
(
1
,
node
[
"followup"
].
as
<
int
>
());
}
TEST
(
LoadNodeTest
,
BlockCREncoded
)
{
Node
node
=
Load
(
"blockText: |
\r
"
" some arbitrary text
\r
"
" spanning some
\r
"
" lines, that are split
\r
"
" by CR and NL
\r
"
"followup: 1"
);
EXPECT_EQ
(
"some arbitrary text
\n
spanning some
\n
lines, that are split
\n
by CR and "
"NL
\n
"
,
node
[
"blockText"
].
as
<
std
::
string
>
());
EXPECT_EQ
(
1
,
node
[
"followup"
].
as
<
int
>
());
}
}
// namespace
}
// namespace YAML
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