# HG changeset patch # User jwe # Date 1142482147 0 # Node ID 9c9eac3a6513aae8b7253b682841eac0e5ae35bc # Parent c5f6623514c4780410752e15f38be95cb635f80e [project @ 2006-03-16 04:09:07 by jwe] diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- 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 * miscellaneous/doc.m: New file. diff --git a/scripts/strings/lower.m b/scripts/strings/lower.m --- 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 diff --git a/scripts/strings/strcmpi.m b/scripts/strings/strcmpi.m --- 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 diff --git a/scripts/strings/strncmpi.m b/scripts/strings/strncmpi.m --- 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 diff --git a/scripts/strings/upper.m b/scripts/strings/upper.m --- 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