comparison scripts/io/strread.m @ 11343:5e5c513ea4c5

strread.m: Don't require space between format specifiers.
author Ben Abbott <bpabbott@mac.com>
date Fri, 10 Dec 2010 19:59:25 -0500
parents 564e998017f5
children c776f063fefe
comparison
equal deleted inserted replaced
11342:cc7f30d3fd01 11343:5e5c513ea4c5
185 str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]); 185 str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]);
186 str = [str{:}]; 186 str = [str{:}];
187 endif 187 endif
188 188
189 ## Determine the number of words per line 189 ## Determine the number of words per line
190 formatstr = strrep (formatstr, "%", " %");
190 [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+"); 191 [~, ~, ~, fmt_words] = regexp (formatstr, "[^\\s]+");
191 192
192 num_words_per_line = numel (fmt_words); 193 num_words_per_line = numel (fmt_words);
193 for m = 1:numel(fmt_words) 194 for m = 1:numel(fmt_words)
194 ## Convert formats such as "%Ns" to "%s" (see the FIXME below) 195 ## Convert formats such as "%Ns" to "%s" (see the FIXME below)
244 out(cellfun (@isempty, out)) = {""}; 245 out(cellfun (@isempty, out)) = {""};
245 out = strtrim (out); 246 out = strtrim (out);
246 endfunction 247 endfunction
247 248
248 %!test 249 %!test
250 %! [a, b] = strread ("1 2", "%f%f");
251 %! assert (a == 1 && b == 2);
252
253 %!test
249 %! str = "# comment\n# comment\n1 2 3"; 254 %! str = "# comment\n# comment\n1 2 3";
250 %! [a, b] = strread (str, '%d %s', 'commentstyle', 'shell'); 255 %! [a, b] = strread (str, '%d %s', 'commentstyle', 'shell');
251 %! assert (a, [1; 3]); 256 %! assert (a, [1; 3]);
252 %! assert (b, {"2"; ""}); 257 %! assert (b, {"2"; ""});
253 258