3 Copyright (C) 2003, 2005, 2006, 2007 John W. Eaton
5 This file is part of Octave.
7 Octave is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 3 of the License, or (at your
10 option) any later version.
12 Octave is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with Octave; see the file COPYING. If not, see
19 <http://www.gnu.org/licenses/>.
24 #include "ls-ascii-helper.h"
29 // Helper functions when reading from ascii files.
30 // These function take care of CR/LF issues when files are opened in text-mode for reading
32 // Skip characters from stream IS until a newline is reached.
33 // Depending on KEEP_NEWLINE, either eat newline from stream or
37 skip_until_newline( std::istream& is, bool keep_newline )
47 if (c == '\n' || c == '\r')
50 if (keep_newline == false)
52 // eat the CR or LF character
55 // make sure that for binary-mode opened ascii files containing CRLF line endings
56 // we skip the LF after CR...
57 if (c == '\r' && is.peek()=='\n')
59 // yes, LF following CR, eat it...
64 // Newline was found, and read from stream if keep_newline==true, so exit loop
68 // no newline charater peeked, so read it and proceed to next character
76 // If stream IS currently points to a newline (a leftover from a previous read)
77 // then eat newline(s) until a non-newline character is found
80 skip_preceeding_newline( std::istream& is )
87 // Check if IS currently points to newline character
89 if (c == '\n' || c == '\r')
93 // eat the CR or LF character
96 // make sure that for binary-mode opened ascii files containing CRLF line endings
97 // we skip the LF after CR...
98 if (c == '\r' && is.peek() == '\n')
100 // yes, LF following CR, eat it...
104 // Peek into next character
106 // Loop while still a newline ahead
107 } while( c == '\n' || c == '\r' );
114 // Read charaters from stream IS until a newline is reached.
115 // Depending on KEEP_NEWLINE, either eat newline from stream or
117 // Characters read are stored and returned as std::string
120 read_until_newline( std::istream& is, bool keep_newline )
123 return std::string();
126 std::ostringstream buf;
131 if (c == '\n' || c == '\r')
134 if (keep_newline == false)
136 // eat the CR or LF character
139 // make sure that for binary-mode opened ascii files containing CRLF line endings
140 // we skip the LF after CR...
141 if (c == '\r' && is.peek() == '\n')
143 // yes, LF following CR, eat it...
148 // Newline was found, and read from stream if keep_newline==true, so exit loop
153 // no newline charater peeked, so read it, store it, and proceed to next