Mercurial > octave-nkf
diff scripts/io/textscan.m @ 19867:9fc020886ae9
maint: Clean up m-files to follow Octave coding conventions.
Try to trim long lines to < 80 chars.
Use '##' for single line comments.
Use '(...)' around tests for if/elseif/switch/while.
Abut cell indexing operator '{' next to variable.
Abut array indexing operator '(' next to variable.
Use space between negation operator '!' and following expression.
Use two newlines between endfunction and start of %!test or %!demo code.
Remove unnecessary parens grouping between short-circuit operators.
Remove stray extra spaces (typos) between variables and assignment operators.
Remove stray extra spaces from ends of lines.
author | Rik <rik@octave.org> |
---|---|
date | Mon, 23 Feb 2015 14:54:39 -0800 |
parents | 0e1f5a750d00 |
children | e51473fdb622 |
line wrap: on
line diff
--- a/scripts/io/textscan.m Mon Feb 23 16:42:25 2015 +0000 +++ b/scripts/io/textscan.m Mon Feb 23 14:54:39 2015 -0800 @@ -232,7 +232,8 @@ endif else if (! ischar (fid)) - ## Determine EOL from file. Search for EOL candidates in first BUFLENGTH chars + ## Determine EOL from file. + ## Search for EOL candidates in the first BUFLENGTH chars eol_srch_len = min (length (str), BUFLENGTH); ## First try DOS (CRLF) if (! isempty (strfind (str(1 : eol_srch_len), "\r\n"))) @@ -251,7 +252,7 @@ args(end+1:end+2) = {"endofline", eol_char}; endif - if (!ischar (fid)) + if (! ischar (fid)) ## Now that we know what EOL looks like, we can process format_repeat_count. ## FIXME The below isn't ML-compatible: counts lines, not format string uses if (isfinite (nlines) && (nlines >= 0)) @@ -276,11 +277,12 @@ endwhile ## OK, found EOL delimiting last requested line. Compute ptr (incl. EOL) if (isempty (eoi)) - printf ("textscan: format repeat count specified but no endofline found\n"); + disp ("textscan: format repeat count specified but no endofline found"); data_size = nblks * BUFLENGTH + count; else ## Compute data size to read incl complete EOL - data_size = (nblks * BUFLENGTH) + eoi(end + min (nlines, n_eoi) - n_eoi) ... + data_size = (nblks * BUFLENGTH) ... + + eoi(end + min (nlines, n_eoi) - n_eoi) ... + l_eol_char - 1; endif fseek (fid, st_pos, "bof"); @@ -434,12 +436,12 @@ %! assert (a{2}', {'B' 'J' 'R' 'Z'}); %! assert (a{3}', int32 ([16 241 3 0])); -%% Test with default endofline parameter +## Test with default endofline parameter %!test %! c = textscan ("L1\nL2", "%s"); %! assert (c{:}, {"L1"; "L2"}); -%% Test with endofline parameter set to "" (empty) - newline should be in word +## Test with endofline parameter set to "" (empty) - newline should be in word %!test %! c = textscan ("L1\nL2", "%s", "endofline", ""); %! assert (int8 (c{:}{:}), int8 ([ 76, 49, 10, 76, 50 ])); @@ -450,8 +452,8 @@ %! c = textscan (str, "Text%*dText%dText"); %! assert (c{1}, int32 ([2; 4; 0])); +## CollectOutput test %!test -%% CollectOutput test %! b = [10:10:100]; %! b = [b; 8*b/5; 8*b*1000/5]; %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); @@ -460,8 +462,8 @@ %! assert (size (c{3}), [10, 2]); %! assert (size (c{2}), [10, 2]); +## CollectOutput test with uneven column length files %!test -%% CollectOutput test with uneven column length files %! b = [10:10:100]; %! b = [b; 8*b/5; 8*b*1000/5]; %! str = sprintf ("%g miles/hr = %g (%g) kilometers (meters)/hr\n", b); @@ -475,7 +477,7 @@ %! assert (c{2}{11, 1}, "/hr"); %! assert (isempty (c{2}{11, 2}), true); -%% Test input validation +## Test input validation %!error textscan () %!error textscan (single (4)) %!error textscan ({4}) @@ -488,13 +490,13 @@ %! assert (R{1}, int32 (1)); %! assert (isempty (R{2}), true); -%% bug #37023 (actually a strread test) +## bug #37023 (actually a strread test) %!test %! data = textscan(" 1. 1 \n 2 3\n", '%f %f'); %! assert (data{1}, [1; 2], 1e-15); %! assert (data{2}, [1; 3], 1e-15); -%% Whitespace test (bug #37333) using delimiter ";" +## Whitespace test (bug #37333) using delimiter ";" %!test %! tc = []; %! tc{1, 1} = "C:/code;"; @@ -511,7 +513,7 @@ %! assert (strcmp (lh, rh)); %! end -%% Whitespace test (bug #37333), adding multipleDelimsAsOne true arg +## Whitespace test (bug #37333), adding multipleDelimsAsOne true arg %!test %! tc = []; %! tc{1, 1} = "C:/code;"; @@ -528,7 +530,7 @@ %! assert (strcmp (lh, rh)); %! end -%% Whitespace test (bug #37333), adding multipleDelimsAsOne false arg +## Whitespace test (bug #37333), adding multipleDelimsAsOne false arg %!test %! tc = []; %! tc{1, 1} = "C:/code;"; @@ -546,7 +548,7 @@ %! assert (strcmp (lh, rh)); %! end -%% Whitespace test (bug #37333) whitespace "" arg +## Whitespace test (bug #37333) whitespace "" arg %!test %! tc = []; %! tc{1, 1} = "C:/code;"; @@ -562,7 +564,7 @@ %! assert (strcmp (lh, rh)); %! end -%% Whitespace test (bug #37333), whitespace " " arg +## Whitespace test (bug #37333), whitespace " " arg %!test %! tc = []; %! tc{1, 1} = "C:/code;"; @@ -579,7 +581,7 @@ %! assert (strcmp (lh, rh)); %! end -%% Test reading from a real file +## Test reading from a real file %!test %! f = tempname (); %! fid = fopen (f, "w+"); @@ -592,7 +594,7 @@ %! assert (A{1}, [d(1); d(3)], 1e-6); %! assert (A{2}, [d(2); d(4)], 1e-6); -%% Tests reading with empty format, should return proper nr of columns +## Tests reading with empty format, should return proper nr of columns %!test %! f = tempname (); %! fid = fopen (f, "w+"); @@ -606,7 +608,7 @@ %! assert (A{3}, [3 ; 7], 1e-6); %! assert (A{4}, [4 ; 8], 1e-6); -%% Tests reading with empty format; empty fields & incomplete lower row +## Tests reading with empty format; empty fields & incomplete lower row %!test %! f = tempname (); %! fid = fopen (f, "w+"); @@ -617,7 +619,7 @@ %! unlink (f); %! assert (A{1}, [999, 2, 999, 4; 5, 6, 999, 999], 1e-6); -%% Error message tests +## Error message tests %!test %! f = tempname (); @@ -667,24 +669,24 @@ %! unlink (f); %! assert (msg1, lasterr); -%% Bug #41824 +## Bug #41824 %!test %! assert (textscan ("123", "", "whitespace", " "){:}, 123); -%% Bug #42343-1, just test supplied emptyvalue (actually done by strread.m) +## Bug #42343-1, just test supplied emptyvalue (actually done by strread.m) %!test %! assert (textscan (",NaN", "", "delimiter", "," ,"emptyValue" ,Inf), {Inf, NaN}); -%% Bug #42343-2, test padding with supplied emptyvalue (done by textscan.m) +## Bug #42343-2, test padding with supplied emptyvalue (done by textscan.m) %!test %! a = textscan (",1,,4\nInf, ,NaN", "", "delimiter", ",", "emptyvalue", -10); %! assert (cell2mat (a), [-10, 1, -10, 4; Inf, -10, NaN, -10]); -%% Bug #42528 +## Bug #42528 %!test %! assert (textscan ("1i", ""){1}, 0+1i); %! assert (cell2mat (textscan ("3, 2-4i, NaN\n -i, 1, 23.4+2.2i", "")), [3+0i, 2-4i, NaN+0i; 0-i, 1+0i, 23.4+2.2i]); -%% Illegal format specifiers +## Illegal format specifiers %!test %!error <no valid format conversion specifiers> textscan ("1.0", "%z");