# HG changeset patch # User Daniel J Sebald # Date 1511381204 21600 # Node ID ddc91a2ee0e0936d7b8d1465354ae8cfe01892ad # Parent 117107eed917a700eb82e4bb8a17dd6f2743652d Remove all delimiters from whitespace list in textscan function (bug #52479). * oct-stream.cc (textscan::parse_options): After all options have been processed, remove all characters in 'delims' string and all strings in 'delim_list' cell from the 'whitespace' string in case user adds a whitespace character as a delimiter. * file-io.cc (Ftextscan): Add BIST test for bug #52479. diff -r 117107eed917 -r ddc91a2ee0e0 libinterp/corefcn/file-io.cc --- a/libinterp/corefcn/file-io.cc Thu Nov 23 13:33:48 2017 -0800 +++ b/libinterp/corefcn/file-io.cc Wed Nov 22 14:06:44 2017 -0600 @@ -2196,6 +2196,17 @@ ## Check for delimiter after exponent %!assert (textscan ("1e-3|42", "%f", "delimiter", "|"), {[1e-3; 42]}) + +%!test <*52479> +%! str = "\t\ta\tb\tc\n"; +%! ret = textscan (str, "%s", "delimiter", "\t"); +%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }) ; + +%!test <*52479> +%! str = "\t\ta\tb\tc\n"; +%! ret = textscan (str, "%s", "delimiter", {"\t"}); +%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }) ; + */ // These tests have end-comment sequences, so can't just be in a comment diff -r 117107eed917 -r ddc91a2ee0e0 libinterp/corefcn/oct-stream.cc --- a/libinterp/corefcn/oct-stream.cc Thu Nov 23 13:33:48 2017 -0800 +++ b/libinterp/corefcn/oct-stream.cc Wed Nov 22 14:06:44 2017 -0600 @@ -29,6 +29,7 @@ #include #include +#include #include #include #include @@ -3717,6 +3718,24 @@ error ("%s: unrecognized option '%s'", who.c_str (), param.c_str ()); } + // Remove any user-supplied delimiter from whitespace list + for (unsigned int j = 0; j < delims.length (); j++) + { + whitespace.erase (std::remove (whitespace.begin (), + whitespace.end (), + delims[j]), + whitespace.end ()); + } + for (int j = 0; j < delim_list.numel (); j++) + { + std::string delim = delim_list(j).string_value (); + if (delim.length () == 1) + whitespace.erase (std::remove (whitespace.begin (), + whitespace.end (), + delim[0]), + whitespace.end ()); + } + whitespace_table = std::string (256, '\0'); for (unsigned int i = 0; i < whitespace.length (); i++) whitespace_table[whitespace[i]] = '1';