Mercurial > hg > octave-terminal
changeset 10424:0b05b204775b
fix strmatch
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Fri, 19 Mar 2010 07:12:21 +0100 |
parents | dfc662a47b7a |
children | 0677c5d80b77 |
files | scripts/ChangeLog scripts/strings/strmatch.m |
diffstat | 2 files changed, 11 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,8 @@ +2010-03-19 Jaroslav Hajek <highegg@gmail.com> + + * strings/strmatch.m (strtrimr): Rewrite for correct behavior. + Add test. + 2010-03-18 Petr Mikulik <mikulik@physics.muni.cz> * /plot/print.m: Add '-append' option.
--- a/scripts/strings/strmatch.m +++ b/scripts/strings/strmatch.m @@ -90,9 +90,10 @@ ## Removes nuls and blanks from the end of the array function s = strtrimr (s) - i = find (s == "\0" | s == " ", 1, "last"); - if (i) - s = s(1:i); + blnks = s == "\0" | s == " "; + i = find (blnks, 1, "last"); + if (i && all (blnks(i:end))) + s = s(1:i-1); endif endfunction @@ -105,3 +106,5 @@ %!assert (strmatch ("apple", {"apple pie"; "apple juice"; "tomato"}), %! [1; 2]); %!assert (strmatch ("apple pie", "apple"), []); +%!assert (strmatch ("a b", {"a b", "a c", "c d"})); +