[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[changeset] make lower and upper aliases of tolower and toupper
From: |
Thorsten Meyer |
Subject: |
[changeset] make lower and upper aliases of tolower and toupper |
Date: |
Sun, 07 Dec 2008 21:07:48 +0100 |
User-agent: |
Mozilla-Thunderbird 2.0.0.17 (X11/20081018) |
Hi,
here is a changeset that makes the lower and upper functions aliases of tolower
and toupper
respectively (and adds a few tests for tolower and toupper):
tolower and toupper can handle cellstrings themselves now. The only remaining
difference between
tolower and lower is, that lower was more restrictive with respect to the input
arguments: lower
accepts only cellstrings and character arrays, while tolower will take almost
anything.
Thorsten
# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1228679953 -3600
# Node ID 7075eb1acd4f9b7ccea543bf8d62185f2c3ea112
# Parent 4953d034b77bdd8daa1e00c85e133bcf3976b6b6
make upper and lower aliases of toupper and tolower respectively
diff -r 4953d034b77b -r 7075eb1acd4f scripts/ChangeLog
--- a/scripts/ChangeLog Sun Dec 07 15:48:07 2008 +0100
+++ b/scripts/ChangeLog Sun Dec 07 20:59:13 2008 +0100
@@ -0,0 +1,6 @@
+2008-12-07 Thorsten Meyer <address@hidden>
+
+ * strings/lower.m: Remove
+ * strings/upper.m: Remove
+ * strings/Makefile.in: Remove lower.m, upper.m
+
diff -r 4953d034b77b -r 7075eb1acd4f scripts/strings/Makefile.in
--- a/scripts/strings/Makefile.in Sun Dec 07 15:48:07 2008 +0100
+++ b/scripts/strings/Makefile.in Sun Dec 07 20:59:13 2008 +0100
@@ -35,10 +35,10 @@
SOURCES = base2dec.m bin2dec.m blanks.m deblank.m dec2base.m \
dec2bin.m dec2hex.m findstr.m hex2dec.m index.m isletter.m isstrprop.m \
- lower.m mat2str.m regexptranslate.m rindex.m split.m str2double.m \
+ mat2str.m regexptranslate.m rindex.m split.m str2double.m \
str2num.m strcat.m cstrcat.m strcmpi.m strfind.m strjust.m strmatch.m \
strncmpi.m strrep.m strtok.m strtrim.m strtrunc.m strvcat.m \
- substr.m upper.m validatestring.m
+ substr.m validatestring.m
DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
diff -r 4953d034b77b -r 7075eb1acd4f scripts/strings/lower.m
--- a/scripts/strings/lower.m Sun Dec 07 15:48:07 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-## Copyright (C) 1998, 2000, 2004, 2005, 2006, 2007 John W. Eaton
-##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING. If not, see
-## <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {} lower (@var{s})
-## 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
-
-function retval = lower (s)
-
- if (nargin != 1)
- print_usage ();
- endif
-
- if (ischar (s))
- retval = tolower (s);
- elseif (iscellstr (s))
- retval = cellfun (@tolower, s, "UniformOutput", false);
- else
- error ("lower: `s' must be a string or cell array of strings");
- endif
-
-endfunction
diff -r 4953d034b77b -r 7075eb1acd4f scripts/strings/upper.m
--- a/scripts/strings/upper.m Sun Dec 07 15:48:07 2008 +0100
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,42 +0,0 @@
-## Copyright (C) 1998, 2000, 2004, 2005, 2006, 2007 John W. Eaton
-##
-## This file is part of Octave.
-##
-## Octave is free software; you can redistribute it and/or modify it
-## under the terms of the GNU General Public License as published by
-## the Free Software Foundation; either version 3 of the License, or (at
-## your option) any later version.
-##
-## Octave is distributed in the hope that it will be useful, but
-## WITHOUT ANY WARRANTY; without even the implied warranty of
-## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-## General Public License for more details.
-##
-## You should have received a copy of the GNU General Public License
-## along with Octave; see the file COPYING. If not, see
-## <http://www.gnu.org/licenses/>.
-
-## -*- texinfo -*-
-## @deftypefn {Function File} {} upper (@var{s})
-## 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
-
-function retval = upper (s)
-
- if (nargin != 1)
- print_usage ();
- endif
-
- if (ischar (s))
- retval = toupper (s);
- elseif (iscellstr (s))
- retval = cellfun (@toupper, s, "UniformOutput", false);
- else
- error ("upper: `s' must be a string or cell array of strings");
- endif
-
-endfunction
diff -r 4953d034b77b -r 7075eb1acd4f src/ChangeLog
--- a/src/ChangeLog Sun Dec 07 15:48:07 2008 +0100
+++ b/src/ChangeLog Sun Dec 07 20:59:13 2008 +0100
@@ -0,0 +1,5 @@
+2008-12-07 Thorsten Meyer <address@hidden>
+
+ * mappers.cc (Ftolower): Make lower alias of tolower, add tests
+ * mappers.cc (Ftoupper): Make upper alias of toupper, add tests
+
diff -r 4953d034b77b -r 7075eb1acd4f src/mappers.cc
--- a/src/mappers.cc Sun Dec 07 15:48:07 2008 +0100
+++ b/src/mappers.cc Sun Dec 07 20:59:13 2008 +0100
@@ -1569,9 +1569,10 @@
DEFUNX ("tolower", Ftolower, args, ,
"-*- texinfo -*-\n\
@deftypefn {Mapping Function} {} tolower (@var{s})\n\
-Return a copy of the string @var{s}, with each upper-case character\n\
-replaced by the corresponding lower-case one; nonalphabetic characters\n\
-are left unchanged. For example,\n\
address@hidden {Mapping Function} {} lower (@var{s})\n\
+Return a copy of the string or cell string @var{s}, with each upper-case\n\
+character replaced by the corresponding lower-case one; nonalphabetic\n\
+characters are left unchanged. For example,\n\
\n\
@example\n\
tolower (\"MiXeD cAsE 123\")\n\
@@ -1588,12 +1589,33 @@
return retval;
}
+DEFALIAS (lower, tolower);
+
+/*
+
+%!error <Invalid call to tolower.*> tolower();
+%!error <Invalid call to tolower.*> lower();
+%!assert(tolower("OCTAVE"), "octave");
+%!assert(tolower("123OCTave!_&"), "123octave!_&");
+%!assert(tolower({"ABC", "DEF", {"GHI", {"JKL"}}}), {"abc", "def", {"ghi",
{"jkl"}}});
+%!assert(tolower(["ABC"; "DEF"]), ["abc"; "def"]);
+%!assert(tolower({["ABC"; "DEF"]}), {["abc";"def"]});
+%!assert(tolower(68), "d");
+%!assert(tolower({[68, 68; 68, 68]}), {["dd";"dd"]});
+%!test
+%! a(3,3,3,3) = "D";
+%! assert(tolower(a)(3,3,3,3), "d");
+
+*/
+
+
DEFUNX ("toupper", Ftoupper, args, ,
"-*- texinfo -*-\n\
@deftypefn {Built-in Function} {} toupper (@var{s})\n\
-Return a copy of the string @var{s}, with each lower-case character\n\
-replaced by the corresponding upper-case one; nonalphabetic characters\n\
-are left unchanged. For example,\n\
address@hidden {Built-in Function} {} upper (@var{s})\n\
+Return a copy of the string or cell string @var{s}, with each lower-case\n\
+character replaced by the corresponding upper-case one; nonalphabetic\n\
+characters are left unchanged. For example,\n\
\n\
@example\n\
@group\n\
@@ -1612,6 +1634,25 @@
return retval;
}
+DEFALIAS (upper, toupper);
+
+/*
+
+%!error <Invalid call to toupper.*> toupper();
+%!error <Invalid call to toupper.*> upper();
+%!assert(toupper("octave"), "OCTAVE");
+%!assert(toupper("123OCTave!_&"), "123OCTAVE!_&");
+%!assert(toupper({"abc", "def", {"ghi", {"jkl"}}}), {"ABC", "DEF", {"GHI",
{"JKL"}}});
+%!assert(toupper(["abc"; "def"]), ["ABC"; "DEF"]);
+%!assert(toupper({["abc"; "def"]}), {["ABC";"DEF"]});
+%!assert(toupper(100), "D");
+%!assert(toupper({[100, 100; 100, 100]}), {["DD";"DD"]});
+%!test
+%! a(3,3,3,3) = "d";
+%! assert(toupper(a)(3,3,3,3), "D");
+
+*/
+
DEFALIAS (gammaln, lgamma);
DEFALIAS (isfinite, finite);
- [changeset] make lower and upper aliases of tolower and toupper,
Thorsten Meyer <=