Mercurial > octave-dspies
comparison scripts/io/strread.m @ 18860:c32f378e08f3 stable
* strread.m: Process string escapes on single quoted format (bug #42609)
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 25 Jun 2014 17:17:38 -0400 |
parents | 35838f49e2f6 |
children | 589354cf668f |
comparison
equal
deleted
inserted
replaced
18859:35838f49e2f6 | 18860:c32f378e08f3 |
---|---|
188 format = "%f"; | 188 format = "%f"; |
189 endif | 189 endif |
190 | 190 |
191 if (! ischar (str) || ! ischar (format)) | 191 if (! ischar (str) || ! ischar (format)) |
192 error ("strread: STR and FORMAT arguments must be strings"); | 192 error ("strread: STR and FORMAT arguments must be strings"); |
193 endif | |
194 | |
195 if (strcmp (typeinfo (format), "sq_string")) | |
196 format = do_string_escapes (format); | |
193 endif | 197 endif |
194 | 198 |
195 ## Parse format string to compare number of conversion fields and nargout | 199 ## Parse format string to compare number of conversion fields and nargout |
196 nfields = length (strfind (format, "%")) - length (strfind (format, "%*")); | 200 nfields = length (strfind (format, "%")) - length (strfind (format, "%*")); |
197 ## If str only has numeric fields, a (default) format ("%f") will do. | 201 ## If str only has numeric fields, a (default) format ("%f") will do. |
983 %!test | 987 %!test |
984 %! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]); | 988 %! assert (strread (",2,,4\n5,,7,", "", "delimiter", ","), [NaN; 2; NaN; 4; 5; NaN; 7]); |
985 | 989 |
986 %% Test #1 bug #42609 | 990 %% Test #1 bug #42609 |
987 %!test | 991 %!test |
988 %! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", "%f %f %f\n") ; | 992 %! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", "%f %f %f\n"); |
989 %! assert (a, [1; 4; 7]); | 993 %! assert (a, [1; 4; 7]); |
990 %! assert (b, [2; 5; 8]); | 994 %! assert (b, [2; 5; 8]); |
991 %! assert (c, [3; 6; 9]); | 995 %! assert (c, [3; 6; 9]); |
992 | 996 |
993 %% Test #2 bug #42609 | 997 %% Test #2 bug #42609 |
994 %!test | 998 %!test |
995 %! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", "%f %f\n%f") ; | 999 %! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", "%f %f\n%f"); |
1000 %! assert (a, [1;4;7]); | |
1001 %! assert (b, [2; 5; 8]); | |
1002 %! assert (c, [3; 6; 9]); | |
1003 | |
1004 %% Test #3 bug #42609 | |
1005 %!test | |
1006 %! [a, b, c] = strread ("1 2 3\n4 5 6\n7 8 9\n", '%f %f %f\n'); | |
1007 %! assert (a, [1; 4; 7]); | |
1008 %! assert (b, [2; 5; 8]); | |
1009 %! assert (c, [3; 6; 9]); | |
1010 | |
1011 %% Test #3 bug #42609 | |
1012 %!test | |
1013 %! [a, b, c] = strread ("1 2\n3\n4 5\n6\n7 8\n9\n", '%f %f\n%f'); | |
996 %! assert (a, [1;4;7]); | 1014 %! assert (a, [1;4;7]); |
997 %! assert (b, [2; 5; 8]); | 1015 %! assert (b, [2; 5; 8]); |
998 %! assert (c, [3; 6; 9]); | 1016 %! assert (c, [3; 6; 9]); |
999 | 1017 |
1000 %% Unsupported format specifiers | 1018 %% Unsupported format specifiers |