# HG changeset patch # User Rik # Date 1311473929 25200 # Node ID d5d3f04a645fb868d3db36ace2b923af867bcb8b # Parent a319f6835e9bc3028e0783a1cd7469b976bce77e strtrim.m: Make behavior same for cell arrays as for char arrays. Add new tests and clarify documentation about whitespace. strtrim.m: Add vertical tab (\v) and nuls (\0) to regexprep expression for cell arrays. Add more tests. Mention whitespace, not just blanks, in documentation. diff -r a319f6835e9b -r d5d3f04a645f scripts/strings/strtrim.m --- a/scripts/strings/strtrim.m Fri Jul 22 13:14:04 2011 -0700 +++ b/scripts/strings/strtrim.m Sat Jul 23 19:18:49 2011 -0700 @@ -18,7 +18,7 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} strtrim (@var{s}) -## Remove leading and trailing blanks and nulls from @var{s}. If +## Remove leading and trailing whitespace and nulls from @var{s}. If ## @var{s} is a matrix, @var{strtrim} trims each row to the length of ## longest string. If @var{s} is a cell array, operate recursively on ## each element of the cell array. For example: @@ -50,20 +50,27 @@ if (isempty (s) || isempty (k)) s = ""; else - s = s(:,ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); + s = s(:, ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); endif elseif (iscell(s)) - s = regexprep (s, '^\s+|\s+$', ''); + s = regexprep (s, "^[\\s\v\\0]+|[\\s\v\\0]+$", ''); else - error ("strtrim: expecting string argument"); + error ("strtrim: S argument must be a string"); endif endfunction -%!error strtrim(); -%!error strtrim("abc", "def"); + %!assert (strtrim (" abc "), "abc"); +%!assert (strtrim (" "), ""); +%!assert (strtrim ("abc"), "abc"); %!assert (strtrim ([" abc "; " def "]), ["abc "; " def"]); +%!assert (strtrim ({" abc "; " def "}), {"abc"; "def"}); + +%!error strtrim (); +%!error strtrim ("abc", "def"); +%!error strtrim (1); +