Mercurial > hg > octave-terminal
changeset 12937:1eebae7ac5d2
strmatch.m: Trim search pattern of spaces and nulls.
* strmatch.m: Trim search pattern of spaces and nulls
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Mon, 08 Aug 2011 11:19:09 -0700 |
parents | b74cb659e757 |
children | 9f2679a14366 |
files | scripts/sparse/svds.m scripts/strings/strmatch.m |
diffstat | 2 files changed, 6 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/sparse/svds.m +++ b/scripts/sparse/svds.m @@ -251,8 +251,8 @@ %! s = s(idx); %! u = u(:,idx); %! v = v(:,idx); -%! randn ('state', 43); % Initialize to make normest function reproducible -%! rand ('state', 43) +%! randn ('state', 35); % Initialize to make normest function reproducible +%! rand ('state', 35) %! opts.v0 = rand (2*n,1); % Initialize eigs ARPACK starting vector %! % to guarantee reproducible results %!test
--- a/scripts/strings/strmatch.m +++ b/scripts/strings/strmatch.m @@ -25,7 +25,7 @@ ## The second argument @var{A} must be a string, character matrix, or a cell ## array of strings. If the third argument @code{"exact"} is not given, then ## @var{s} only needs to match @var{A} up to the length of @var{s}. -## Trailing spaces and nulls in @var{A} are ignored even with the @code{"exact"} +## Trailing spaces and nulls in @var{s} and @var{A} are ignored when matching. ## option. ## ## For example: @@ -63,6 +63,8 @@ error ("strmatch: A must be a string or cell array of strings"); endif + ## Trim blanks and nulls from search string + s = regexprep (s, "[ \\0]+$", ''); len = length (s); exact = nargin == 3 && ischar (exact) && strcmp (exact, "exact"); @@ -100,7 +102,7 @@ %!assert (strmatch ("apple", ["apple pie"; "apple juice"; "an apple"]), [1; 2]); %!assert (strmatch ("apple", {"apple pie"; "apple juice"; "tomato"}), [1; 2]); %!assert (strmatch ("apple pie", "apple"), []); -%!assert (strmatch ("a ", "a"), []); +%!assert (strmatch ("a ", "a"), 1); %!assert (strmatch ("a", "a \0", "exact"), 1); %!assert (strmatch ("a b", {"a b", "a c", "c d"}), 1); %!assert (strmatch ("", {"", "foo", "bar", ""}), [1, 4]);