Mercurial > hg > octave-lyh
comparison scripts/io/textscan.m @ 16311:9c4ac8f25a8c
textscan.m, textread.m: fix wrong code assessing EOL char(s), remove duplicate code
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Fri, 15 Mar 2013 09:54:53 +0100 |
parents | 23636765e00a |
children | 0cbe330f39a2 |
comparison
equal
deleted
inserted
replaced
16310:e7f6c479ce1c | 16311:9c4ac8f25a8c |
---|---|
209 else | 209 else |
210 if (! ischar (fid)) | 210 if (! ischar (fid)) |
211 ## Determine EOL from file. Search for EOL candidates in first BUFLENGTH chars | 211 ## Determine EOL from file. Search for EOL candidates in first BUFLENGTH chars |
212 eol_srch_len = min (length (str), BUFLENGTH); | 212 eol_srch_len = min (length (str), BUFLENGTH); |
213 ## First try DOS (CRLF) | 213 ## First try DOS (CRLF) |
214 if (! isempty (strfind ("\r\n", str(1 : eol_srch_len)))) | 214 if (! isempty (strfind (str(1 : eol_srch_len), "\r\n"))) |
215 eol_char = "\r\n"; | 215 eol_char = "\r\n"; |
216 ## Perhaps old Macintosh? (CR) | 216 ## Perhaps old Macintosh? (CR) |
217 elseif (! isempty (strfind ("\r", str(1 : eol_srch_len)))) | 217 elseif (! isempty (strfind (str(1 : eol_srch_len), "\r"))) |
218 eol_char = "\r"; | 218 eol_char = "\r"; |
219 ## Otherwise, use plain UNIX (LF) | 219 ## Otherwise, use plain UNIX (LF) |
220 else | 220 else |
221 eol_char = "\n"; | 221 eol_char = "\n"; |
222 endif | 222 endif |
265 fseek (fid, st_pos, "bof"); | 265 fseek (fid, st_pos, "bof"); |
266 str = fread (fid, "char=>char").'; | 266 str = fread (fid, "char=>char").'; |
267 endif | 267 endif |
268 endif | 268 endif |
269 | 269 |
270 ## Determine the number of data fields | |
271 num_fields = numel (strfind (format, "%")) - numel (strfind (format, "%*")); | |
272 | |
273 ## Strip trailing EOL to avoid returning stray missing values (f. strread). | 270 ## Strip trailing EOL to avoid returning stray missing values (f. strread). |
274 ## However, in case of CollectOutput request, presence of EOL is required | 271 ## However, in case of CollectOutput request, presence of EOL is required |
275 eol_at_end = strcmp (str(end-length (eol_char) + 1 : end), eol_char); | 272 eol_at_end = strcmp (str(end-length (eol_char) + 1 : end), eol_char); |
276 if (collop) | 273 if (collop) |
277 if (! eol_at_end) | 274 if (! eol_at_end) |