Mercurial > hg > octave-terminal
changeset 7429:744f522dbabe
[project @ 2008-01-30 07:44:07 by jwe]
author | jwe |
---|---|
date | Wed, 30 Jan 2008 07:44:07 +0000 |
parents | 0c11c6907c38 |
children | 8b7c7998d78f |
files | scripts/ChangeLog scripts/strings/deblank.m |
diffstat | 2 files changed, 38 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,7 @@ +2008-01-30 John W. Eaton <jwe@octave.org> + + * strings/deblank.m: Improve compatibility. + 2008-01-29 John W. Eaton <jwe@octave.org> * strings/str2double.m: Delete unused variable FLAG_OCTAVE.
--- a/scripts/strings/deblank.m +++ b/scripts/strings/deblank.m @@ -34,13 +34,23 @@ print_usage (); endif - if (ischar (s)) + char_arg = ischar (s); + + if (char_arg || isnumeric (s)) - k = find (! isspace (s) & s != "\0"); - if (isempty (s) || isempty (k)) - s = ""; - else - s = s(:,1:ceil (max (k) / rows (s))); + if (! isempty (s)) + if (char_arg) + k = find (! isspace (s) & s != "\0"); + else + warning ("deblank: expecting character string argument") + k = find (s != 0); + endif + + if (isempty (k)) + s = resize (s, 0, 0); + else + s = s(:,1:ceil (max (k) / rows (s))); + endif endif elseif (iscell(s)) @@ -48,16 +58,29 @@ s = cellfun (@deblank, s, "UniformOutput", false); else - error ("deblank: expecting string argument"); + error ("deblank: expecting character string argument"); endif endfunction -%!assert(strcmp (deblank (" f o o "), " f o o")); +%!assert (strcmp (deblank (" f o o "), " f o o")); + +%!assert (deblank ([]), []) +%!assert (deblank ({}), {}) +%!assert (deblank (""), "") + +%!assert (deblank ([0,0,0]), []) +%!assert (deblank (' '), '') +%!assert (deblank (" "), "") + +%!assert (typeinfo (deblank (" ")), "string") +%!assert (typeinfo (deblank (' ')), "sq_string") + +%!assert (deblank ([1,2,0]), [1,2]) +%!assert (deblank ([1,2,0,32]), [1,2,0,32]) + +%!assert (deblank (int8 ([1,2,0])), int8 ([1,2])) %!error deblank (); %!error deblank ("foo", "bar"); - -%!error deblank (1); -