diff scripts/strings/strmatch.m @ 11323:d7fbb08e28cf

strmatch.m: avoid passing length of 0 to strncmp
author John W. Eaton <jwe@octave.org>
date Wed, 08 Dec 2010 03:25:04 -0500
parents 01ddaedd6ad5
children 7bb759d617e2
line wrap: on
line diff
--- a/scripts/strings/strmatch.m	Wed Dec 08 02:45:48 2010 -0500
+++ b/scripts/strings/strmatch.m	Wed Dec 08 03:25:04 2010 -0500
@@ -64,7 +64,11 @@
   exact = nargin == 3 && ischar (exact) && strcmp (exact, "exact");
 
   if (iscell (A))
-    idx = find (strncmp (s, A, len));
+    if (len > 0)
+      idx = find (strncmp (s, A, len));
+    else
+      idx = find (strcmp (s, A));
+    endif
     if (exact)
       ## We can't just use strcmp, because we need to ignore whitespace.
       B = cellfun (@strtrimr, A(idx), "uniformoutput", false);
@@ -107,4 +111,4 @@
 %!        [1; 2]);
 %!assert (strmatch ("apple pie", "apple"), []);
 %!assert (strmatch ("a b", {"a b", "a c", "c d"}));
-
+%!assert (strmatch ("", {"", "foo", "bar", ""}), [1, 4])