diff scripts/io/strread.m @ 14800:a922f768ee09

textscan, strread: improved ML compatibility (bug 36398) * textscan: check for empty data string after removal of trailing EOL * strread: check for incomplete very first data line while parsing + add 2 tests
author Philip Nienhuis <prnienhuis@users.sf.net>
date Fri, 22 Jun 2012 20:01:35 +0200
parents 21197c43f984
children d5aee269b770
line wrap: on
line diff
--- a/scripts/io/strread.m	Fri Jun 22 19:09:30 2012 +0200
+++ b/scripts/io/strread.m	Fri Jun 22 20:01:35 2012 +0200
@@ -459,7 +459,8 @@
       ## Alternative below goes by simply parsing a first grab of words
       ## and counting words until the fmt_words array is exhausted:
       iwrd = 1; iwrdp = 0; iwrdl = length (words{iwrd});
-      for ii = 1:numel (fmt_words)
+      ii = 1;
+      while ii <= numel (fmt_words)
 
         nxt_wrd = 0;
 
@@ -521,12 +522,16 @@
 
         if (nxt_wrd)
           ++iwrd; iwrdp = 0;
-          if (ii < numel (fmt_words))
+          if (iwrd > numel (words))
+            ## Apparently EOF; assume incomplete row already at L.1 of data
+            ii = numel (fmt_words);
+          elseif (ii < numel (fmt_words))
             iwrdl = length (words{iwrd});
           endif
         endif
+        ++ii;
 
-      endfor
+      endwhile
       ## Done
       words_period = max (iwrd - 1, 1);
       num_lines = ceil (num_words / words_period);
@@ -910,6 +915,16 @@
 %! assert (c, [0.94; 0.87], 0.01)
 
 %!test
+%! [a, b] = strread (['Empty 1' char(10)], 'Empty%s %f');
+%! assert (a{1}, '1');
+%! assert (b, NaN);
+
+%!test
+%! [a, b] = strread (['Empty' char(10)], 'Empty%f %f');
+%! assert (a, NaN);
+%! assert (b, NaN);
+
+%!test
 %! # Bug #35999
 %! [a, b, c] = strread ("", "%f");
 %! assert (isempty (a));