Mercurial > hg > octave-lyh
changeset 11935:8bc4e0ae758c release-3-0-x
handle CRLF and CR in fgetl/fgets
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 23 Feb 2009 21:04:10 +0100 |
parents | 7518126401ac |
children | e896fba7e3d4 |
files | src/ChangeLog src/oct-stream.cc |
diffstat | 2 files changed, 29 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +2009-02-13 John W. Eaton <jwe@octave.org> + + * oct-stream.cc (octave_base_stream::do_gets): Handle CRLF and CR. + 2009-01-23 Jaroslav Hajek <highegg@gmail.com> * DLD-FUNCTIONS/ranpd.cc: Use relative tolerance for randp tests.
--- a/src/oct-stream.cc +++ b/src/oct-stream.cc @@ -982,7 +982,31 @@ { char_count++; - if (c == '\n') + // Handle CRLF, CR, or LF as line ending. + + if (c == '\r') + { + if (! strip_newline) + buf << static_cast<char> (c); + + c = is.get (); + + if (c != EOF) + { + if (c == '\n') + { + char_count++; + + if (! strip_newline) + buf << static_cast<char> (c); + } + else + is.putback (c); + } + + break; + } + else if (c == '\n') { if (! strip_newline) buf << static_cast<char> (c);