changeset 21551:990c6c31a684

Accept escape sequences in single quoted strings for "delimiter" (bug #47539) * oct-stream.cc (textscan::parse_options): call do_string_escapes for "delimiter". * file-io.cc: Add BIST tests.
author Lachlan Andrew <lachlanbis@gmail.com>
date Sat, 26 Mar 2016 18:14:31 +1100
parents 7ebd8ac26178
children 102b33b53ea4
files libinterp/corefcn/file-io.cc libinterp/corefcn/oct-stream.cc
diffstat 2 files changed, 13 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc	Sun Feb 14 10:12:30 2016 +1100
+++ b/libinterp/corefcn/file-io.cc	Sat Mar 26 18:14:31 2016 +1100
@@ -1977,6 +1977,14 @@
 %! assert (C{3}', [13, 24, 35]);
 %! assert (C{4}', [15, 25, NaN]);
 
+## Single-quoted escape sequences
+%!test
+%! str = "11\t12\t13\r21\t22\t23";
+%! c = textscan (str, "", "delimiter", '\t', "EndOfLine", '\r');
+%! assert (c{1}', [11, 21]);
+%! assert (c{2}', [12, 22]);
+%! assert (c{3}', [13, 23]);
+
 ## Bug #44750
 %!test
 %! assert (textscan ("/home/foo/", "%s", "delimiter", "/", "MultipleDelimsAsOne", 1){1}, ...
--- a/libinterp/corefcn/oct-stream.cc	Sun Feb 14 10:12:30 2016 +1100
+++ b/libinterp/corefcn/oct-stream.cc	Sat Mar 26 18:14:31 2016 +1100
@@ -3585,6 +3585,8 @@
               invalid = false;
               have_delims = true;
               delims = args(i+1).string_value ();
+              if (args(i+1).is_sq_string ())
+                delims = do_string_escapes (delims);
             }
           else if (args(i+1).is_cell ())
             {
@@ -3599,6 +3601,9 @@
                     invalid = true;
                   else
                     {
+                      if (delim_list(j).is_sq_string ())
+                        delim_list(j) = do_string_escapes (delim_list(j)
+                                                           .string_value ());
                       octave_idx_type len = delim_list(j).string_value ()
                                                          .length ();
                       delim_len = std::max (static_cast<int> (len), delim_len);