Mercurial > hg > octave-terminal
changeset 12879:c3b305e7e59f
maint: Reverse previous changeset 875c735c0929
strread.m: Reverse previous changeset which contained some unintended elements.
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sun, 24 Jul 2011 22:00:15 -0700 |
parents | 875c735c0929 |
children | ff264eae88cf |
files | scripts/io/strread.m |
diffstat | 1 files changed, 16 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/strread.m +++ b/scripts/io/strread.m @@ -26,10 +26,9 @@ ## ## The string @var{str} is split into words that are repeatedly matched to the ## specifiers in @var{format}. The first word is matched to the first -## specifier, -## the second to the second specifier and so forth. If there are more words -## than -## specifiers, the process is repeated until all words have been processed. +## specifier, the second to the second specifier and so forth. If there are +## more words than specifiers, the process is repeated until all words have +## been processed. ## ## The string @var{format} describes how the words in @var{str} should be ## parsed. @@ -224,9 +223,12 @@ case "returnonerror" err_action = varargin{n+1}; case "treatasempty" - empty_str = varargin{n+1}; - if (ischar (empty_str)) - empty_str = {empty_str}; + if (iscellstr (varargin{n+1})) + empty_str = varargin{n+1}; + elseif (ischar (varargin{n+1})) + empty_str = varargin(n+1); + else + error ('strread: "treatasempty" value must be string or cellstr'); endif otherwise warning ('strread: unknown property "%s"', varargin{n}); @@ -234,11 +236,7 @@ endfor ## Parse format string to compare nr. of conversion fields and nargout - idx = strfind (format, "%")'; - specif = format([idx, idx+1]); - nspecif = length (idx); - idx_star = strfind (format, "%*"); - nfields = length (idx) - length (idx_star); + nfields = length (strfind (format, "%")) - length (strfind (format, "%*")); ## If str only has numeric fields, a (default) format ("%f") will do. ## Otherwise: if ((max (nargout, 1) != nfields) && ! strcmp (format, "%f")) @@ -300,6 +298,7 @@ if (! isempty (white_spaces)) ## Check for overlapping whitespaces and delimiters & trim whitespace + ## FIXME: Can this section be replaced by call to setdiff() ? if (! isempty (delimiter_str)) [ovlp, iw] = intersect (white_spaces, delimiter_str); if (! isempty (ovlp)) @@ -357,15 +356,12 @@ endif num_words = numel (words); ## First guess at number of lines in file (ignoring leading/trailing literals) - if (format_repeat_count > 0) - num_lines = format_repeat_count; - else - num_lines = ceil (num_words / num_words_per_line); - endif + num_lines = ceil (num_words / num_words_per_line); ## Replace TreatAsEmpty char sequences by empty strings if (! isempty (empty_str)) ## FIXME: There should be a simpler way to do this with cellfun + ## or possibly with regexprep for ii = 1:numel (empty_str) idz = strmatch (empty_str{ii}, words, "exact"); words(idz) = {""}; @@ -397,7 +393,7 @@ ## 1. Assess "period" in the split-up words array ( < num_words_per_line). ## Could be done using EndOfLine but that prohibits EndOfLine = "" option. fmt_in_word = cell (num_words_per_line, 1); - words_period = 1; + words_period = litptr = 1; ## For each literal in turn for ii = 1:numel (idy) fmt_in_word(idy(ii)) = num_words; @@ -411,9 +407,7 @@ endif endfor words_period = max (words_period, litptr); - if (format_repeat_count < 0) - num_lines = ceil (num_words / words_period); - endif + num_lines = ceil (num_words / words_period); ## 2. Pad words array so that it can be reshaped tmp_lines = ceil (num_words / words_period); @@ -498,7 +492,7 @@ end_try_catch endif - + ## For each specifier, process corresponding column k = 1; for m = 1:num_words_per_line @@ -697,5 +691,3 @@ %! c = textscan (str, "Text%*dText%dText"); %! assert (c{1}, [2; 4; NaN]); -%!assert (isequal (strread ("1 2 3 4", "%d", 2), [1; 2])) -