Mercurial > octave-nkf
changeset 19732:4aa17069a007
Fix incorrect strread behavior with option "commentstyle" (bug #43972)
* scripts/io/strread.m: Added a check to prevent the last char of a comment
to be considered not part of the comment itself.
author | Massimiliano Fasi <massimiliano.fasi@gmail.com> |
---|---|
date | Fri, 30 Jan 2015 09:06:37 +0100 |
parents | 4197fc428c7d |
children | 2e9f17872f36 |
files | scripts/io/strread.m |
diffstat | 1 files changed, 15 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/io/strread.m Wed Feb 11 14:19:08 2015 -0500 +++ b/scripts/io/strread.m Fri Jan 30 09:06:37 2015 +0100 @@ -373,6 +373,10 @@ endif len = length (str); c2len = length (comment_end); + if (cstop + c2len == len) + ## Ignore last char of to-the-end-of-line comments + c2len++; + end str = cellslices (str, [1, cstop + c2len], [cstart - 1, len]); str = [str{:}]; endif @@ -844,6 +848,17 @@ %! assert (b, {"2"}); %!test +%! assert (strread ("Hello World! // this is comment", "%s",... +%! "commentstyle", "c++"), ... +%! {"Hello"; "World!"}); +%! assert (strread ("Hello World! % this is comment", "%s",... +%! "commentstyle", "matlab"), ... +%! {"Hello"; "World!"}); +%! assert (strread ("Hello World! # this is comment", "%s",... +%! "commentstyle", "shell"), ... +%! {"Hello"; "World!"}); + +%!test %! str = sprintf ("Tom 100 miles/hr\nDick 90 miles/hr\nHarry 80 miles/hr"); %! fmt = "%s %f miles/hr"; %! c = cell (1, 2);