Mercurial > hg > octave-terminal
changeset 5676:9c9eac3a6513
[project @ 2006-03-16 04:09:07 by jwe]
author | jwe |
---|---|
date | Thu, 16 Mar 2006 04:09:07 +0000 |
parents | c5f6623514c4 |
children | a8f6903535c9 |
files | scripts/ChangeLog scripts/strings/lower.m scripts/strings/strcmpi.m scripts/strings/strncmpi.m scripts/strings/upper.m |
diffstat | 5 files changed, 34 insertions(+), 8 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -4,6 +4,8 @@ * strings/strncmpi.m: Import from octave-forge, simplify. * strings/strtrunc.m: New function. + * strings/lower.m, strings/upper.m: Handle cellstr arguments. + 2006-03-15 John W. Eaton <jwe@octave.org> * miscellaneous/doc.m: New file.
--- a/scripts/strings/lower.m +++ b/scripts/strings/lower.m @@ -19,8 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} lower (@var{s}) -## Transform all letters in the string @var{s} to lower case. -## @seealso{tolower} +## Transform all letters in the character string (or cell array of +## character strings) @var{s} to lower case. +## @seealso{upper, tolower, toupper} ## @end deftypefn ## Author: jwe @@ -31,6 +32,15 @@ usage ("lower (s)"); endif - retval = tolower (s); + if (ischar (s)) + retval = tolower (s); + elseif (iscellstr (s)) + retval = cell (size (s)); + for i = 1:(numel (s)) + retval{i} = tolower(s{i}); + endfor + else + error ("lower: `s' must be a string or cell array of strings"); + endif endfunction
--- a/scripts/strings/strcmpi.m +++ b/scripts/strings/strcmpi.m @@ -40,7 +40,9 @@ function retval = strcmpi (s1, s2) if (nargin == 2) - retval = strcmp (tolower (s1), tolower (s2)); + ## Note that we don't use tolower here because we need to be able to + ## handle cell arrays of strings. + retval = strcmp (lower (s1), lower (s2)); else usage ("strcmpi (s1, s2)"); endif
--- a/scripts/strings/strncmpi.m +++ b/scripts/strings/strncmpi.m @@ -37,7 +37,9 @@ function retval = strncmpi (s1, s2, n) if (nargin == 3) - retval = strcmp (tolower (strtrunc (s1, n)), tolower (strtrunc (s2, n))); + ## Note that we don't use tolower here because we need to be able to + ## handle cell arrays of strings. + retval = strcmp (lower (strtrunc (s1, n)), lower (strtrunc (s2, n))); else usage ("strncmpi (s1, s2, n)"); endif
--- a/scripts/strings/upper.m +++ b/scripts/strings/upper.m @@ -19,8 +19,9 @@ ## -*- texinfo -*- ## @deftypefn {Function File} {} upper (@var{s}) -## Transform all letters in the string @var{s} to upper case. -## @seealso{toupper} +## Transform all letters in the character string (or cell array of +## character strings) @var{s} to upper case. +## @seealso{lower, tolower, toupper} ## @end deftypefn ## Author: jwe @@ -31,6 +32,15 @@ usage ("upper (s)"); endif - retval = toupper (s); + if (ischar (s)) + retval = toupper (s); + elseif (iscellstr (s)) + retval = cell (size (s)); + for i = 1:(numel (s)) + retval{i} = toupper(s{i}); + endfor + else + error ("upper: `s' must be a string or cell array of strings"); + endif endfunction