Mercurial > octave-nkf
changeset 20239:935832827f47 stable
textread.m: properly initialize endofline if specified by user (bug #45046)
author | Philip Nienhuis <prnienhuis@users.sf.net> |
---|---|
date | Tue, 19 May 2015 20:19:45 +0200 |
parents | b7ee5cefa9d6 |
children | 59911f536b07 |
files | scripts/io/textread.m |
diffstat | 1 files changed, 20 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/textread.m Mon May 18 19:14:41 2015 -0400 +++ b/scripts/io/textread.m Tue May 19 20:19:45 2015 +0200 @@ -115,7 +115,12 @@ endofline = find (strcmpi (varargin, "endofline"), 1); if (! isempty (endofline)) ## 'endofline' option set by user. - if (! ischar (varargin{endofline + 1})); + if (ischar (varargin{endofline + 1})) + eol_char = varargin{endofline + 1}; + if (! any (strcmp (eol_char, {"", "\n", "\r", "\r\n"}))) + error ("textscan: illegal EndOfLine character value specified"); + endif + else error ("character value required for EndOfLine"); endif else @@ -310,6 +315,20 @@ %! unlink (f); %! assert (A, [0 2 0 4; 5 0 0 0], 1e-6); +## Test endofline +%!test +%! f = tempname (); +%! fid = fopen (f, "w"); +%! fprintf (fid, "a\rb\rc"); +%! fclose (fid); +%! ## Test EOL detection +%! d = textread (f, "%s"); +%! assert (d, {"a";"b";"c"}); +%! ## Test explicit EOL specification (bug #45046) +%! d = textread (f, "%s", "endofline", "\r"); +%! assert (d, {"a"; "b"; "c"}); +%! unlink (f); + ## Test input validation %!error textread () %!error textread (1)