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	Thu Mar 18 20:08:35 2010 -0400
+++ b/scripts/ChangeLog	Fri Mar 19 07:12:21 2010 +0100
@@ -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	Thu Mar 18 20:08:35 2010 -0400
+++ b/scripts/strings/strmatch.m	Fri Mar 19 07:12:21 2010 +0100
@@ -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"}));
+