comparison scripts/io/textscan.m @ 18582:2ce1f1966fc3 stable

textscan.m: Fix undefined whitespace error with empty format input (bug #41824). * textscan.m: Define whitespace variable even when format string is empty. Add %!test for behavior.
author Sergey Plotnikov
date Tue, 11 Mar 2014 21:44:38 +0100
parents 1c89599167a6
children 8354510f95ab
comparison
equal deleted inserted replaced
18578:02a61d7c2de0 18582:2ce1f1966fc3
1 ## Copyright (C) 2010-2013 Ben Abbott 1 ## Copyright (C) 2010-2014 Ben Abbott
2 ## 2 ##
3 ## This file is part of Octave. 3 ## This file is part of Octave.
4 ## 4 ##
5 ## Octave is free software; you can redistribute it and/or modify it 5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by 6 ## under the terms of the GNU General Public License as published by
133 ## If there is a string format AND whitespace value = empty, 133 ## If there is a string format AND whitespace value = empty,
134 ## don't add a space (char(32)) to whitespace 134 ## don't add a space (char(32)) to whitespace
135 if (! (isempty (args{ipos+1}) && has_str_fmt)) 135 if (! (isempty (args{ipos+1}) && has_str_fmt))
136 args{ipos+1} = unique ([" ", args{ipos+1}]); 136 args{ipos+1} = unique ([" ", args{ipos+1}]);
137 endif 137 endif
138 whitespace = args{ipos+1};
138 endif 139 endif
139 140
140 if (! any (strcmpi (args, "delimiter"))) 141 if (! any (strcmpi (args, "delimiter")))
141 ## Matlab says default delimiter = whitespace. 142 ## Matlab says default delimiter = whitespace.
142 ## strread() will pick this up further 143 ## strread() will pick this up further
659 %! end_try_catch; 660 %! end_try_catch;
660 %! fclose (fid); 661 %! fclose (fid);
661 %! unlink (f); 662 %! unlink (f);
662 %! assert (msg1, lasterr); 663 %! assert (msg1, lasterr);
663 664
665 %% Bug #41824
666 %!test
667 %! assert (textscan ("123", "", "whitespace", " "){:}, 123);
668