From 211a7f57be1913a32239b9868c85f18cd6b28683 Mon Sep 17 00:00:00 2001 From: Jay Berkenbilt Date: Mon, 13 Jan 2020 09:16:43 -0500 Subject: QUtil::read_lines_from_file: optional EOL preservation --- libqpdf/QUtil.cc | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'libqpdf/QUtil.cc') diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 42647504..70066b32 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -1116,11 +1116,18 @@ QUtil::read_lines_from_file(std::function next_char, } if (c == '\n') { - // Remove any carriage return that preceded the - // newline and discard the newline - if ((! buf->empty()) && ((*(buf->rbegin())) == '\r')) + if (preserve_eol) { - buf->erase(buf->length() - 1); + buf->append(1, c); + } + else + { + // Remove any carriage return that preceded the + // newline and discard the newline + if ((! buf->empty()) && ((*(buf->rbegin())) == '\r')) + { + buf->erase(buf->length() - 1); + } } buf = 0; } -- cgit v1.2.3-54-g00ecf