"...composable_kernel.git" did not exist on "d1db6a0c3ea190996bdae37adda191f746bfc34e"
Commit ee9c4d19 authored by Simon Gene Gottlieb's avatar Simon Gene Gottlieb Committed by Jesse Beder
Browse files

fix: parse files with '\r' symbols as line ending correctly

parent b38ac5b5
...@@ -262,7 +262,24 @@ char Stream::get() { ...@@ -262,7 +262,24 @@ char Stream::get() {
AdvanceCurrent(); AdvanceCurrent();
m_mark.column++; 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.column = 0;
m_mark.line++; m_mark.line++;
} }
......
...@@ -53,6 +53,7 @@ class Stream { ...@@ -53,6 +53,7 @@ class Stream {
Mark m_mark; Mark m_mark;
CharacterSet m_charSet; CharacterSet m_charSet;
char m_lineEndingSymbol{}; // 0 means it is not determined yet, must be '\n' or '\r'
mutable std::deque<char> m_readahead; mutable std::deque<char> m_readahead;
unsigned char* const m_pPrefetched; unsigned char* const m_pPrefetched;
mutable size_t m_nPrefetchedAvailable; mutable size_t m_nPrefetchedAvailable;
......
...@@ -360,5 +360,21 @@ TEST(LoadNodeTest, BlockCRNLEncoded) { ...@@ -360,5 +360,21 @@ TEST(LoadNodeTest, BlockCRNLEncoded) {
EXPECT_EQ(1, node["followup"].as<int>()); 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 \nspanning some \nlines, that are split \nby CR and "
"NL\n",
node["blockText"].as<std::string>());
EXPECT_EQ(1, node["followup"].as<int>());
}
} // namespace } // namespace
} // namespace YAML } // namespace YAML
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment