Mercurial > hg > octave-nkf
comparison scripts/io/strread.m @ 13141:e81ddf9cacd5
maint: untabify and remove trailing whitespace from source files
* bicg.m, gmres.m, pkg.m: Untabify and remove trailing whitespace.
* libcruft/Makefile.am, libcruft/blas-xtra/cdotc3.f,
libcruft/blas-xtra/cmatm3.f, libcruft/blas-xtra/ddot3.f,
libcruft/blas-xtra/dmatm3.f, libcruft/blas-xtra/sdot3.f,
libcruft/blas-xtra/smatm3.f, libcruft/blas-xtra/zdotc3.f,
libcruft/blas-xtra/zmatm3.f, libcruft/lapack-xtra/crsf2csf.f,
libcruft/lapack-xtra/zrsf2csf.f, liboctave/Array.cc,
liboctave/DASPK-opts.in, liboctave/DASRT-opts.in,
liboctave/DASSL-opts.in, liboctave/LSODE-opts.in,
liboctave/Makefile.a,mliboctave/Quad-opts.in,
liboctave/Sparse-perm-op-defs.h,
scripts/Makefile.a,mscripts/deprecated/glpkmex.m,
scripts/general/blkdiag.m, scripts/general/interp1.m,
scripts/general/profshow.m, scripts/general/quadl.m,
scripts/general/triplequad.m, scripts/help/__makeinfo__.m,
scripts/io/strread.m, scripts/io/textread.m, scripts/io/textscan.m,
scripts/linear-algebra/rank.m, scripts/miscellaneous/gzip.m,
scripts/miscellaneous/private/__xzip__.m,
scripts/miscellaneous/tempdir.m, scripts/miscellaneous/unpack.m,
scripts/pkg/pkg.m, scripts/plot/allchild.m, scripts/plot/ancestor.m,
scripts/plot/cla.m, scripts/plot/clf.m, scripts/plot/findall.m,
scripts/plot/findobj.m, scripts/plot/gca.m, scripts/plot/gcf.m,
scripts/plot/hggroup.m, scripts/plot/isfigure.m,
scripts/plot/ishghandle.m, scripts/plot/legend.m,
scripts/plot/line.m, scripts/plot/loglog.m, scripts/plot/patch.m,
scripts/plot/print.m, scripts/plot/private/__quiver__.m,
scripts/plot/private/__scatter__.m, scripts/plot/rectangle.m,
scripts/plot/semilogx.m, scripts/plot/semilogy.m,
scripts/plot/surface.m, scripts/plot/text.m, scripts/plot/title.m,
scripts/plot/trisurf.m, scripts/plot/view.m, scripts/plot/whitebg.m,
scripts/plot/xlabel.m, scripts/plot/xlim.m, scripts/plot/ylabel.m,
scripts/plot/ylim.m, scripts/plot/zlabel.m, scripts/plot/zlim.m,
scripts/polynomial/mkpp.m, scripts/polynomial/polygcd.m,
scripts/polynomial/ppint.m, scripts/polynomial/ppjumps.m,
scripts/polynomial/ppval.m, scripts/set/setxor.m,
scripts/sparse/bicgstab.m, scripts/sparse/cgs.m,
scripts/sparse/spconvert.m, scripts/specfun/nthroot.m,
scripts/strings/strmatch.m, scripts/strings/untabify.m,
scripts/testfun/demo.m, scripts/testfun/example.m,
src/DLD-FUNCTIONS/filter.cc, src/DLD-FUNCTIONS/mgorth.cc,
src/DLD-FUNCTIONS/quadcc.cc, src/DLD-FUNCTIONS/str2double.cc,
src/Makefile.a,msrc/gl-render.cc, src/gl2ps-renderer.cc,
src/graphics.cc, src/octave-config.cc.in, src/octave-config.in,
src/ov-class.h, src/ov-fcn.h, src/profiler.cc, src/profiler.h,
src/pt-binop.cc, src/pt-unop.cc, src/symtab.cc, src/txt-eng-ft.cc:
Remove trailing whitespace.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 15 Sep 2011 12:51:10 -0400 |
parents | 3509cf60d1f6 |
children | 9b8e786bbf3c |
comparison
equal
deleted
inserted
replaced
13140:98d23b0f16e1 | 13141:e81ddf9cacd5 |
---|---|
118 ## (2) 2x1 cell string array: Everything between the left and right strings | 118 ## (2) 2x1 cell string array: Everything between the left and right strings |
119 ## is skipped. | 119 ## is skipped. |
120 ## @end itemize | 120 ## @end itemize |
121 ## | 121 ## |
122 ## @item "delimiter" | 122 ## @item "delimiter" |
123 ## Any character in @var{value} will be used to split @var{str} into words | 123 ## Any character in @var{value} will be used to split @var{str} into words |
124 ## (default value = any whitespace). | 124 ## (default value = any whitespace). |
125 ## | 125 ## |
126 ## @item "emptyvalue" | 126 ## @item "emptyvalue" |
127 ## Parts of the output where no word is available is filled with @var{value}. | 127 ## Parts of the output where no word is available is filled with @var{value}. |
128 ## | 128 ## |
129 ## @item "multipledelimsasone" | 129 ## @item "multipledelimsasone" |
130 ## Treat a series of consecutive delimiters, without whitespace in between, | 130 ## Treat a series of consecutive delimiters, without whitespace in between, |
131 ## as a single delimiter. Consecutive delimiter series need not be vertically | 131 ## as a single delimiter. Consecutive delimiter series need not be vertically |
132 ## "aligned". | 132 ## "aligned". |
133 ## | 133 ## |
134 ## @item "treatasempty" | 134 ## @item "treatasempty" |
135 ## Treat single occurrences (surrounded by delimiters or whitespace) of the | 135 ## Treat single occurrences (surrounded by delimiters or whitespace) of the |
136 ## string(s) in @var{value} as missing values. | 136 ## string(s) in @var{value} as missing values. |
142 ## @item "whitespace" | 142 ## @item "whitespace" |
143 ## Any character in @var{value} will be interpreted as whitespace and | 143 ## Any character in @var{value} will be interpreted as whitespace and |
144 ## trimmed; the string defining whitespace must be enclosed in double | 144 ## trimmed; the string defining whitespace must be enclosed in double |
145 ## quotes for proper processing of special characters like \t. | 145 ## quotes for proper processing of special characters like \t. |
146 ## The default value for whitespace = " \b\r\n\t" (note the space). | 146 ## The default value for whitespace = " \b\r\n\t" (note the space). |
147 ## | 147 ## |
148 ## @end table | 148 ## @end table |
149 ## | 149 ## |
150 ## @seealso{textscan, textread, load, dlmread, fscanf} | 150 ## @seealso{textscan, textread, load, dlmread, fscanf} |
151 ## @end deftypefn | 151 ## @end deftypefn |
152 | 152 |
218 elseif (iscellstr (varargin{n+1}) && numel (varargin{n+1}) == 2) | 218 elseif (iscellstr (varargin{n+1}) && numel (varargin{n+1}) == 2) |
219 [comment_start, comment_end] = deal (varargin{n+1}{:}); | 219 [comment_start, comment_end] = deal (varargin{n+1}{:}); |
220 else | 220 else |
221 ## FIXME - a user may have numeric values specified: {'//', 7} | 221 ## FIXME - a user may have numeric values specified: {'//', 7} |
222 ## this will lead to an error in the warning message | 222 ## this will lead to an error in the warning message |
223 error ("strread: unknown or unrecognized comment style '%s'", | 223 error ("strread: unknown or unrecognized comment style '%s'", |
224 varargin{n+1}); | 224 varargin{n+1}); |
225 endif | 225 endif |
226 endswitch | 226 endswitch |
227 case "delimiter" | 227 case "delimiter" |
228 delimiter_str = varargin{n+1}; | 228 delimiter_str = varargin{n+1}; |
288 endif | 288 endif |
289 | 289 |
290 ## Remove comments in str | 290 ## Remove comments in str |
291 if (comment_flag) | 291 if (comment_flag) |
292 ## Expand 'eol_char' here, after option processing which may have set value | 292 ## Expand 'eol_char' here, after option processing which may have set value |
293 comment_end = regexprep (comment_end, 'eol_char', eol_char); | 293 comment_end = regexprep (comment_end, 'eol_char', eol_char); |
294 cstart = strfind (str, comment_start); | 294 cstart = strfind (str, comment_start); |
295 cstop = strfind (str, comment_end); | 295 cstop = strfind (str, comment_end); |
296 ## Treat end of string as additional comment stop | 296 ## Treat end of string as additional comment stop |
297 if (isempty (cstop) || cstop(end) != length (str)) | 297 if (isempty (cstop) || cstop(end) != length (str)) |
298 cstop(end+1) = length (str); | 298 cstop(end+1) = length (str); |
337 ## Trim whitespace if needed | 337 ## Trim whitespace if needed |
338 ## FIXME: This is very complicated. Can this be simplified with regexprep? | 338 ## FIXME: This is very complicated. Can this be simplified with regexprep? |
339 if (! isempty (white_spaces)) | 339 if (! isempty (white_spaces)) |
340 ## Check if trailing "\n" might signal padding output arrays to equal size | 340 ## Check if trailing "\n" might signal padding output arrays to equal size |
341 ## before it is trimmed away below | 341 ## before it is trimmed away below |
342 if ((str(end) == 10) && (nargout > 1)) | 342 if ((str(end) == 10) && (nargout > 1)) |
343 pad_out = 1; | 343 pad_out = 1; |
344 endif | 344 endif |
345 ## Remove repeated white_space chars. First find white_space positions | 345 ## Remove repeated white_space chars. First find white_space positions |
346 idx = strchr (str, white_spaces); | 346 idx = strchr (str, white_spaces); |
347 ## Find repeated white_spaces | 347 ## Find repeated white_spaces |
382 for ii = 1:numel (empty_str) | 382 for ii = 1:numel (empty_str) |
383 idz = strmatch (empty_str{ii}, words, "exact"); | 383 idz = strmatch (empty_str{ii}, words, "exact"); |
384 words(idz) = {""}; | 384 words(idz) = {""}; |
385 endfor | 385 endfor |
386 endif | 386 endif |
387 | 387 |
388 ## We now may have to cope with 3 cases: | 388 ## We now may have to cope with 3 cases: |
389 ## A: Trailing literals (%f<literal>) w/o delimiter in between. | 389 ## A: Trailing literals (%f<literal>) w/o delimiter in between. |
390 ## B: Leading literals (<literal>%f) w/o delimiter in between. | 390 ## B: Leading literals (<literal>%f) w/o delimiter in between. |
391 ## C. Skipping leftover parts of specified skip fields (%*N ) | 391 ## C. Skipping leftover parts of specified skip fields (%*N ) |
392 ## fmt_words has been split properly now, but words{} has only been split on | 392 ## fmt_words has been split properly now, but words{} has only been split on |
396 | 396 |
397 ## Find indices and pointers to possible literals in fmt_words | 397 ## Find indices and pointers to possible literals in fmt_words |
398 idf = cellfun ("isempty", strfind (fmt_words, "%")); | 398 idf = cellfun ("isempty", strfind (fmt_words, "%")); |
399 ## Find indices and pointers to conversion specifiers with fixed width | 399 ## Find indices and pointers to conversion specifiers with fixed width |
400 idg = ! cellfun ("isempty", regexp (fmt_words, '%\*?\d')); | 400 idg = ! cellfun ("isempty", regexp (fmt_words, '%\*?\d')); |
401 idy = find (idf | idg); | 401 idy = find (idf | idg); |
402 | 402 |
403 ## If needed, split up columns in three steps: | 403 ## If needed, split up columns in three steps: |
404 if (! isempty (idy)) | 404 if (! isempty (idy)) |
405 ## Try-catch because complexity of strings to read can be infinite | 405 ## Try-catch because complexity of strings to read can be infinite |
406 #try | 406 #try |
407 | 407 |
408 ## 1. Assess "period" in the split-up words array ( < num_words_per_line). | 408 ## 1. Assess "period" in the split-up words array ( < num_words_per_line). |
409 ## Could be done using EndOfLine but that prohibits EndOfLine = "" option. | 409 ## Could be done using EndOfLine but that prohibits EndOfLine = "" option. |
410 ## Alternative below goes by simply parsing a first grab of words | 410 ## Alternative below goes by simply parsing a first grab of words |
444 error ("strread: Field width '%s' (fmt spec # %d) extends beyond word limit", fmt_words{ii}, ii); | 444 error ("strread: Field width '%s' (fmt spec # %d) extends beyond word limit", fmt_words{ii}, ii); |
445 elseif (iwrdp == iwrdl) | 445 elseif (iwrdp == iwrdl) |
446 ## Word completely "used up". Next word | 446 ## Word completely "used up". Next word |
447 ++iwrd; iwrdp = 0; iwrdl = length (words{iwrd}); | 447 ++iwrd; iwrdp = 0; iwrdl = length (words{iwrd}); |
448 endif | 448 endif |
449 | 449 |
450 else | 450 else |
451 ## A simple format conv. specifier. Either (1) uses rest of word, or | 451 ## A simple format conv. specifier. Either (1) uses rest of word, or |
452 ## (2) is squeezed between current iwrdp and next literal, or (3) uses | 452 ## (2) is squeezed between current iwrdp and next literal, or (3) uses |
453 ## next word. (3) is already taken care of. So just check (1) & (2) | 453 ## next word. (3) is already taken care of. So just check (1) & (2) |
454 if (ii < numel (fmt_words) && idf(ii+1)) | 454 if (ii < numel (fmt_words) && idf(ii+1)) |
460 ## ..or it IS found. Add inferred width of current conversion field | 460 ## ..or it IS found. Add inferred width of current conversion field |
461 iwrdp += index (words{iwrd}(iwrdp+1:end), fmt_words{ii+1}) - 1; | 461 iwrdp += index (words{iwrd}(iwrdp+1:end), fmt_words{ii+1}) - 1; |
462 endif | 462 endif |
463 elseif (iwrdp < iwrdl) | 463 elseif (iwrdp < iwrdl) |
464 ## No bordering literal to the right => field occupies (rest of) word | 464 ## No bordering literal to the right => field occupies (rest of) word |
465 ++iwrd; iwrdp = 0; | 465 ++iwrd; iwrdp = 0; |
466 if (ii < numel (fmt_words)) | 466 if (ii < numel (fmt_words)) |
467 iwrdl = length (words{iwrd}); | 467 iwrdl = length (words{iwrd}); |
468 endif | 468 endif |
469 endif | 469 endif |
470 | 470 |
476 | 476 |
477 ## 2. Pad words array so that it can be reshaped | 477 ## 2. Pad words array so that it can be reshaped |
478 tmp_lines = ceil (num_words / words_period); | 478 tmp_lines = ceil (num_words / words_period); |
479 num_words_padded = tmp_lines * words_period - num_words; | 479 num_words_padded = tmp_lines * words_period - num_words; |
480 if (num_words_padded) | 480 if (num_words_padded) |
481 words = [words'; cell(num_words_padded, 1)]; | 481 words = [words'; cell(num_words_padded, 1)]; |
482 endif | 482 endif |
483 words = reshape (words, words_period, tmp_lines); | 483 words = reshape (words, words_period, tmp_lines); |
484 | 484 |
485 ## 3. Do the column splitting on rectangular words array | 485 ## 3. Do the column splitting on rectangular words array |
486 icol = 1; ii = 1; # icol = current column, ii = current fmt_word | 486 icol = 1; ii = 1; # icol = current column, ii = current fmt_word |
496 s = s{:}(1); | 496 s = s{:}(1); |
497 e = s(1) + length (fmt_words{ii}) - 1; | 497 e = s(1) + length (fmt_words{ii}) - 1; |
498 endif | 498 endif |
499 if (! strcmp (fmt_words{ii}, words{icol, 1})) | 499 if (! strcmp (fmt_words{ii}, words{icol, 1})) |
500 ## Column doesn't exactly match literal => split needed. Insert a column | 500 ## Column doesn't exactly match literal => split needed. Insert a column |
501 words(icol+1:end+1, :) = words(icol:end, :); | 501 words(icol+1:end+1, :) = words(icol:end, :); |
502 ## Watch out for empty cells | 502 ## Watch out for empty cells |
503 jptr = find (! cellfun ("isempty", words(icol, :))); | 503 jptr = find (! cellfun ("isempty", words(icol, :))); |
504 | 504 |
505 ## Distinguish leading or trailing literals | 505 ## Distinguish leading or trailing literals |
506 if (! idg(ii) && ! isempty (s) && s(1) == 1) | 506 if (! idg(ii) && ! isempty (s) && s(1) == 1) |
521 elseif (idg(ii)) | 521 elseif (idg(ii)) |
522 ## Current field = fixed width. Strip into icol, rest in icol+1 | 522 ## Current field = fixed width. Strip into icol, rest in icol+1 |
523 wdth = floor (str2double (fmt_words{ii}(regexp(fmt_words{ii}, ... | 523 wdth = floor (str2double (fmt_words{ii}(regexp(fmt_words{ii}, ... |
524 '\d') : end-1))); | 524 '\d') : end-1))); |
525 words(icol+1, jptr) = cellfun (@(x) x(wdth+1:end), | 525 words(icol+1, jptr) = cellfun (@(x) x(wdth+1:end), |
526 words(icol,jptr), "UniformOutput", false); | 526 words(icol,jptr), "UniformOutput", false); |
527 words(icol, jptr) = strtrunc (words(icol, jptr), wdth); | 527 words(icol, jptr) = strtrunc (words(icol, jptr), wdth); |
528 else | 528 else |
529 ## FIXME: this assumes char(254)/char(255) won't occur in input! | 529 ## FIXME: this assumes char(254)/char(255) won't occur in input! |
530 clear wrds; | 530 clear wrds; |
531 wrds(1:2:2*numel (words(icol, jptr))) = ... | 531 wrds(1:2:2*numel (words(icol, jptr))) = ... |
564 # warning ("strread: unable to parse text or file with given format string"); | 564 # warning ("strread: unable to parse text or file with given format string"); |
565 # return; | 565 # return; |
566 | 566 |
567 #end_try_catch | 567 #end_try_catch |
568 endif | 568 endif |
569 | 569 |
570 ## For each specifier, process corresponding column | 570 ## For each specifier, process corresponding column |
571 k = 1; | 571 k = 1; |
572 for m = 1:num_words_per_line | 572 for m = 1:num_words_per_line |
573 try | 573 try |
574 if (format_repeat_count < 0) | 574 if (format_repeat_count < 0) |
585 ## FIXME - add support for formats like "<%s>", "%[a-zA-Z]" | 585 ## FIXME - add support for formats like "<%s>", "%[a-zA-Z]" |
586 ## Someone with regexp experience is needed. | 586 ## Someone with regexp experience is needed. |
587 switch fmt_words{m}(1:min (2, length (fmt_words{m}))) | 587 switch fmt_words{m}(1:min (2, length (fmt_words{m}))) |
588 case "%s" | 588 case "%s" |
589 if (pad_out) | 589 if (pad_out) |
590 data(end+1:num_lines) = {""}; | 590 data(end+1:num_lines) = {""}; |
591 endif | 591 endif |
592 varargout{k} = data'; | 592 varargout{k} = data'; |
593 k++; | 593 k++; |
594 case {"%d", "%u", "%f", "%n"} | 594 case {"%d", "%u", "%f", "%n"} |
595 n = cellfun ("isempty", data); | 595 n = cellfun ("isempty", data); |
596 ### FIXME - erroneously formatted data lead to NaN, not an error | 596 ### FIXME - erroneously formatted data lead to NaN, not an error |
597 data = str2double (data); | 597 data = str2double (data); |
598 if (! isempty (regexp (fmt_words{m}, "%[du]"))) | 598 if (! isempty (regexp (fmt_words{m}, "%[du]"))) |
599 ## Cast to integer | 599 ## Cast to integer |
600 ## FIXME: NaNs will be transformed into zeros | 600 ## FIXME: NaNs will be transformed into zeros |
601 data = int32 (data); | 601 data = int32 (data); |
602 end | 602 end |
603 data(n) = numeric_fill_value; | 603 data(n) = numeric_fill_value; |
604 if (pad_out) | 604 if (pad_out) |
621 endif | 621 endif |
622 if (numel (nfmt) > 1) | 622 if (numel (nfmt) > 1) |
623 sprec = str2double (nfmt{2}); | 623 sprec = str2double (nfmt{2}); |
624 data = 10^-sprec * round (10^sprec * data); | 624 data = 10^-sprec * round (10^sprec * data); |
625 elseif (! isempty (regexp (fmt_words{m}, "[du]"))) | 625 elseif (! isempty (regexp (fmt_words{m}, "[du]"))) |
626 ## Cast to integer | 626 ## Cast to integer |
627 ## FIXME: NaNs will be transformed into zeros | 627 ## FIXME: NaNs will be transformed into zeros |
628 data = int32 (data); | 628 data = int32 (data); |
629 end | 629 end |
630 varargout{k} = data.'; | 630 varargout{k} = data.'; |
631 k++; | 631 k++; |
680 out = strsplit (text, sep, mult_dlms_s1); | 680 out = strsplit (text, sep, mult_dlms_s1); |
681 ## In case of trailing delimiter, strip stray last empty word | 681 ## In case of trailing delimiter, strip stray last empty word |
682 if (!isempty (out) && any (sep == text(end))) | 682 if (!isempty (out) && any (sep == text(end))) |
683 out(end) = []; | 683 out(end) = []; |
684 endif | 684 endif |
685 | 685 |
686 ## Empty cells converted to empty cellstrings. | 686 ## Empty cells converted to empty cellstrings. |
687 out(cellfun ("isempty", out)) = {""}; | 687 out(cellfun ("isempty", out)) = {""}; |
688 | 688 |
689 endfunction | 689 endfunction |
690 | 690 |