# HG changeset patch # User Rik # Date 1311473995 25200 # Node ID 787a84da70a65acd37456a134af3dc745c59ea92 # Parent e8c8e118a1e6e9fd786ba85358c3fb37de1f2d7b# Parent d5d3f04a645fb868d3db36ace2b923af867bcb8b maint: Periodic merge of stable to default diff --git a/scripts/strings/strtrim.m b/scripts/strings/strtrim.m --- a/scripts/strings/strtrim.m +++ b/scripts/strings/strtrim.m @@ -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); +