changeset 20728:ab0d9d7f479c stable

textread.m, textscan.m: properly process single-quoted endofline parameter (bug #46477)
author Philip Nienhuis <prnienhuis@users.sf.net>
date Fri, 20 Nov 2015 11:37:48 +0100
parents 234589c84d4a
children 5e2da9a66510 fdffc955b4ed
files scripts/io/textread.m scripts/io/textscan.m
diffstat 2 files changed, 23 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/io/textread.m	Thu Nov 19 08:21:01 2015 -0800
+++ b/scripts/io/textread.m	Fri Nov 20 11:37:48 2015 +0100
@@ -163,6 +163,9 @@
     ## 'endofline' option set by user.
     if (ischar (varargin{endofline + 1}))
       eol_char = varargin{endofline + 1};
+      if (strcmp (typeinfo (eol_char), "sq_string"))
+        eol_char = do_string_escapes (eol_char);
+      endif
       if (! any (strcmp (eol_char, {"", "\n", "\r", "\r\n"})))
         error ("textscan: illegal EndOfLine character value specified");
       endif
@@ -478,6 +481,16 @@
 %! assert (d, {"a"; "b"; "c"});
 %! unlink (f);
 
+## Properly process single-quoted EOL args (bug #46477)
+%!test
+%! f = tempname ();
+%! fid = fopen (f, "w");
+%! fprintf (fid, "hello, world!");
+%! fclose (fid);
+%! [a, b] = textread (f, "%s%s", "endofline", '\n');
+%! assert (a{1}, "hello,");
+%! assert (b{1}, "world!");
+
 ## Test input validation
 %!error textread ()
 %!error textread (1)
--- a/scripts/io/textscan.m	Thu Nov 19 08:21:01 2015 -0800
+++ b/scripts/io/textscan.m	Fri Nov 20 11:37:48 2015 +0100
@@ -224,6 +224,9 @@
   if (! isempty (endofline))
     if (ischar (args{endofline + 1}))
       eol_char = args{endofline + 1};
+      if (strcmp (typeinfo (eol_char), "sq_string"))
+        eol_char = do_string_escapes (eol_char);
+      endif
       if (! any (strcmp (eol_char, {"", "\n", "\r", "\r\n"})))
         error ("textscan: illegal EndOfLine character value specified");
       endif
@@ -696,3 +699,10 @@
 ## Illegal format specifiers
 %!test
 %!error <no valid format conversion specifiers> textscan ("1.0", "%z");
+
+## Properly process single-quoted EOL args (bug #46477)
+%!test
+%! C = textscan ("hello, world!", "%s%s", "endofline", '\n');
+%! assert (C{1}{1}, "hello,");
+%! assert (C{2}{1}, "world!");
+