# HG changeset patch # User Massimiliano Fasi # Date 1422605197 -3600 # Node ID 4aa17069a0071dd00b23eafbd4bf8e11ec8e2fcb # Parent 4197fc428c7d89932d2c4a4602bc1d94eefa9f33 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. diff -r 4197fc428c7d -r 4aa17069a007 scripts/io/strread.m --- 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);