aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2017-04-22 11:52:44 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2017-04-22 11:52:44 +0200
commiteb4810893eb4c8379c3455f1e8a75ccd3b911aa6 (patch)
treeb2ead0b0ee2a14849a731d604b534ba4b13bb3db
parentc1d5be099ecd2a0d4e120360bae24582723f1153 (diff)
Fix Windows CR/LF handling
-rw-r--r--butl/char-scanner4
-rw-r--r--butl/char-scanner.cxx24
2 files changed, 15 insertions, 13 deletions
diff --git a/butl/char-scanner b/butl/char-scanner
index 7dc56fa..cbeca96 100644
--- a/butl/char-scanner
+++ b/butl/char-scanner
@@ -20,8 +20,8 @@ namespace butl
{
public:
// If the crlf argument is true, then recognize Windows newlines (0x0D
- // 0x0A) and convert them to just '\n' (0x0A). Note that standalone 0x0D
- // that are not followed by 0x0A are returned as is.
+ // 0x0A) and convert them to just '\n' (0x0A). Note that a standalone
+ // 0x0D is treated "as if" it was followed by 0x0A.
//
char_scanner (std::istream& is, bool crlf = true)
: is_ (is), crlf_ (crlf) {}
diff --git a/butl/char-scanner.cxx b/butl/char-scanner.cxx
index b923aa6..8be7520 100644
--- a/butl/char-scanner.cxx
+++ b/butl/char-scanner.cxx
@@ -25,6 +25,19 @@ namespace butl
if (v == xchar::traits_type::eof ())
eos_ = true;
+ else if (crlf_ && v == 0x0D)
+ {
+ is_.get ();
+ xchar::int_type v1 (is_.peek ());
+
+ if (v1 != '\n')
+ {
+ unget_ = true;
+ buf_ = '\n';
+ }
+
+ v = '\n';
+ }
return xchar (v, line, column);
}
@@ -53,17 +66,6 @@ namespace butl
{
is_.get ();
- if (crlf_ && c == 0x0D)
- {
- xchar c1 (peek ());
-
- if (c1 == '\n')
- {
- is_.get ();
- c = c1;
- }
- }
-
if (c == '\n')
{
line++;