diff libinterp/corefcn/file-io.cc @ 24346:f77da8da0f3f

Fix textscan missing fields and number reads for cell-specified delimiters (bug #52550). * oct-stream.cc (textscan::read_double): Remove what looks like repetitive code hunk concerning reading INF and NAN. (textscan::read_until): Treat eol1 and eol2 as delimiters. When no valid data is found between delimiters, put the delimiter symbol back into the stream since the ensuing skip_delimiter() call will be removing it. (textscan::scan_string): Add eol1 and eol2 characters to "ends" string array. (textscan::read_format_once): Distinguish between the cell-specified and string-specified delimiter scenario. For cell-specified delimiters, use the tellg-seekg restoration of the stream position similar to what is present inside lookahead(). * file-io.cc (Ftextscan): Add BIST tests for bug #52550.
author Daniel J Sebald <daniel.sebald@ieee.org>
date Fri, 01 Dec 2017 17:28:37 -0600
parents 4dce9d03b2ba
children c341ebb40ede
line wrap: on
line diff
--- a/libinterp/corefcn/file-io.cc	Thu Nov 30 22:57:15 2017 +0100
+++ b/libinterp/corefcn/file-io.cc	Fri Dec 01 17:28:37 2017 -0600
@@ -2214,12 +2214,44 @@
 %!test <*52479>
 %! str = "\t\ta\tb\tc\n";
 %! ret = textscan (str, "%s", "delimiter", "\t");
-%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }) ;
+%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} });
 
 %!test <52479>
 %! str = "\t\ta\tb\tc\n";
 %! ret = textscan (str, "%s", "delimiter", {"\t"});
-%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} }) ;
+%! assert (ret, { {''; ''; 'a'; 'b'; 'c'} });
+
+%!test <52550>
+%! str = ",,1,2,3\n";
+%! obs = textscan (str, "%d", "delimiter", ",");
+%! assert (obs, { [0; 0; 1; 2; 3] });
+%! obs = textscan (str, "%d", "delimiter", {","});
+%! assert (obs, { [0; 0; 1; 2; 3] });
+
+%!test <52550>
+%! str = " , ,1,2,3\n";
+%! obs = textscan (str, "%d", "delimiter", ",");
+%! assert (obs, { [0; 0; 1; 2; 3] });
+%! textscan (str, "%d", "delimiter", {","});
+%! assert (obs, { [0; 0; 1; 2; 3] });
+
+%!test <52550>
+%! str = " 0 , 5+6j , -INF+INFj ,NaN,3\n";
+%! obs = textscan (str, "%f", "delimiter", ",");
+%! assert (obs, { [0; 5+6i; complex(-Inf,Inf); NaN; 3] });
+%! obs = textscan (str, "%f", "delimiter", {","});
+%! assert (obs, { [0; 5+6i; complex(-Inf,Inf); NaN; 3] });
+
+%!test <52550>
+%! str = " 0;,;,1;,2;,3\n";
+%! assert (textscan (str, "%f", "delimiter", {";,"}), { [0; NaN; 1; 2; 3] });
+
+%!test <52550>
+%! str = " 0 ;1 , $ 2 ;3\n";
+%! obs = textscan (str, "%f", "delimiter", ",;$");
+%! assert (obs, { [0; 1; NaN; 2; 3] });
+%! obs = textscan (str, "%f", "delimiter", {",",";","$"});
+%! assert (obs, { [0; 1; NaN; 2; 3] });
 
 */