Mercurial > hg > octave-lyh
changeset 12875:787a84da70a6
maint: Periodic merge of stable to default
author | Rik <octave@nomad.inbox5.com> |
---|---|
date | Sat, 23 Jul 2011 19:19:55 -0700 |
parents | e8c8e118a1e6 (current diff) d5d3f04a645f (diff) |
children | 29cd5a828bb2 |
files | |
diffstat | 1 files changed, 13 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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 <Invalid call to strtrim> strtrim(); -%!error <Invalid call to strtrim> 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 <Invalid call to strtrim> strtrim (); +%!error <Invalid call to strtrim> strtrim ("abc", "def"); +%!error <argument must be a string> strtrim (1); +