diff options
author | Jay Berkenbilt <ejb@ql.org> | 2020-01-13 15:16:43 +0100 |
---|---|---|
committer | Jay Berkenbilt <ejb@ql.org> | 2020-01-13 17:26:18 +0100 |
commit | 211a7f57be1913a32239b9868c85f18cd6b28683 (patch) | |
tree | 496fc07c16e80e373fe3bde3b68f147155f41fe9 /libqpdf/QUtil.cc | |
parent | 9a398504ca869e00de15c713108264e0beead504 (diff) | |
download | qpdf-211a7f57be1913a32239b9868c85f18cd6b28683.tar.zst |
QUtil::read_lines_from_file: optional EOL preservation
Diffstat (limited to 'libqpdf/QUtil.cc')
-rw-r--r-- | libqpdf/QUtil.cc | 15 |
1 files changed, 11 insertions, 4 deletions
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<bool(char&)> 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; } |