octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [changeset] make str2mat an alias of char


From: Thorsten Meyer
Subject: Re: [changeset] make str2mat an alias of char
Date: Tue, 02 Dec 2008 21:37:53 +0100
User-agent: Mozilla-Thunderbird 2.0.0.17 (X11/20081018)

address@hidden wrote:
> Looking at 
> 
> http://www.mathworks.com/access/helpdesk/help/techdoc/ref/str2mat.html
> 
> it seems that str2mat is considered as obselete. I'd therefore be 
> inclined to move str2mat to scripts/deprecated but written as something
> like
> 
> function varargout = str2mat (varargin)
>   persistent warned = false;
>   if (! warned)
>     warned = true;
>     warning ("Octave:deprecated-function",
>              "str2mat is obsolete and will be removed from a future 
> version of Octave; please use char instead");
>   endif
> 
>   varargout = cell (nargout, 1);
>   [ varargout{:} ] = char (varargin{:});
> 
> endfunction
> 
> 
Fine with me. See the attached patch (had to replace varargout by a fixed output
argument to keep behaviour on the command line).

Thorsten
# HG changeset patch
# User Thorsten Meyer <address@hidden>
# Date 1228249350 -3600
# Node ID 16a19b3040e0def94ba3b9813f7d74263c1a4129
# Parent  f8ef2a2c44ce3ecf73196ec8715b5664eceb2abd
move str2mat to deprecated and make it a simple wrapper around char

diff -r f8ef2a2c44ce -r 16a19b3040e0 doc/ChangeLog
--- a/doc/ChangeLog     Sun Nov 30 22:49:16 2008 +0100
+++ b/doc/ChangeLog     Tue Dec 02 21:22:30 2008 +0100
@@ -1,3 +1,8 @@
+2008-12-02  Thorsten Meyer  <address@hidden>
+
+        * doc/interpreter/container.txi, doc/interpreter/strings.txi:
+        Remove reference to str2mat.m
+        
 2008-11-15  Thorsten Meyer  <address@hidden>
 
         * interpreter/strings.txi: Add text around docstrings, change
diff -r f8ef2a2c44ce -r 16a19b3040e0 doc/interpreter/container.txi
--- a/doc/interpreter/container.txi     Sun Nov 30 22:49:16 2008 +0100
+++ b/doc/interpreter/container.txi     Tue Dec 02 21:22:30 2008 +0100
@@ -665,7 +665,7 @@
 @noindent
 The following functions for string manipulation support cell arrays of
 strings, @code{strcmp}, @code{strcmpi}, @code{strncmp}, @code{strncmpi}, 
address@hidden, @code{str2mat}, @code{strappend}, @code{strtrunc},
address@hidden, @code{char}, @code{strappend}, @code{strtrunc},
 @code{strvcat}, @code{strfind}, and @code{strmatch}.
 
 @DOCSTRING(cellstr)
diff -r f8ef2a2c44ce -r 16a19b3040e0 doc/interpreter/strings.txi
--- a/doc/interpreter/strings.txi       Sun Nov 30 22:49:16 2008 +0100
+++ b/doc/interpreter/strings.txi       Tue Dec 02 21:22:30 2008 +0100
@@ -224,7 +224,7 @@
 
 It has been shown above that strings can be concatenated using matrix notation
 (@pxref{Strings}, @ref{Character Arrays}).  Apart from that, there are several
-functions to concatenate string objects: @code{char}, @code{str2mat},
+functions to concatenate string objects: @code{char},
 @code{strvcat}, @code{strcat} and @code{cstrcat}.  In addition, the general
 purpose concatenation functions can be used: see @ref{doc-cat,,cat},
 @ref{doc-horzcat,,horzcat} and @ref{doc-vertcat,,vertcat}.
@@ -243,7 +243,7 @@
 @end example
 
 @item
address@hidden, @code{str2mat} and @code{strvcat}
address@hidden and @code{strvcat}
 concatenate vertically, while @code{strcat} and @code{cstrcat} concatenate
 horizontally.  For example:
 
@@ -262,7 +262,7 @@
 @end group
 @end example
 
address@hidden @code{char} and @code{str2mat} both generate an empty row in the 
output
address@hidden @code{char} generates an empty row in the output
 for each empty string in the input.  @code{strvcat}, on the other hand,
 eliminates empty strings.
 
@@ -286,7 +286,7 @@
 @end example
 
 @item All string concatenation functions except @code{cstrcat} also accept cell
-array data (@pxref{Cell Arrays}).  @code{char}, @code{str2mat} and
+array data (@pxref{Cell Arrays}).  @code{char} and
 @code{strvcat} convert cell arrays into character arrays, while @code{strcat}
 concatenates within the cells of the cell arrays:
 
@@ -336,8 +336,6 @@
 @end itemize
 
 @DOCSTRING(char)
-
address@hidden(str2mat)
 
 @DOCSTRING(strvcat)
 
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/ChangeLog
--- a/scripts/ChangeLog Sun Nov 30 22:49:16 2008 +0100
+++ b/scripts/ChangeLog Tue Dec 02 21:22:30 2008 +0100
@@ -1,3 +1,12 @@
+2008-12-02  Thorsten Meyer  <address@hidden>
+
+        * scripts/strings/str2mat.m: Make it a simple wrapper around
+        char() and move it to scripts/deprecated/str2mat.m, remove
+        obsolete tests, move remaining test to src/strfns.cc (Fchar).
+        * scripts/strings/Makefile.in: Remove str2mat.m.
+        * scripts/deprecated/Makefile.in: Add str2mat.m.
+        * scripts/strings/strvcat.m: Remove reference to str2mat.
+        
 2008-11-28  David Bateman  <address@hidden>
 
        * plot/__go_draw_axes__.m: Set two point clipping mode to be on.
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/deprecated/Makefile.in
--- a/scripts/deprecated/Makefile.in    Sun Nov 30 22:49:16 2008 +0100
+++ b/scripts/deprecated/Makefile.in    Tue Dec 02 21:22:30 2008 +0100
@@ -53,7 +53,7 @@
   struct_contains.m struct_elements.m t_cdf.m t_inv.m t_pdf.m \
   t_rnd.m uniform_cdf.m uniform_inv.m uniform_pdf.m uniform_rnd.m \
   weibcdf.m weibinv.m weibpdf.m weibrnd.m weibull_cdf.m \
-  weibull_inv.m weibull_pdf.m weibull_rnd.m wiener_rnd.m
+  weibull_inv.m weibull_pdf.m weibull_rnd.m wiener_rnd.m str2mat.m
 
 DISTFILES = $(addprefix $(srcdir)/, Makefile.in $(SOURCES))
 
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/deprecated/str2mat.m
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/scripts/deprecated/str2mat.m      Tue Dec 02 21:22:30 2008 +0100
@@ -0,0 +1,44 @@
+## Copyright (C) 1996, 1998, 1999, 2000, 2002, 2004, 2005, 2006, 2007
+##               Kurt Hornik
+##
+## 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} {} str2mat (@var{s_1}, @dots{}, @var{s_n})
+## Return a matrix containing the strings @var{s_1}, @dots{}, @var{s_n} as
+## its rows.  Each string is padded with blanks in order to form a valid
+## matrix.
+##
+## This function is modelled after @sc{Matlab}.  In Octave, you can create
+## a matrix of strings by @address@hidden; @dots{}; @var{s_n}]} even if
+## the strings are not all the same length.
+## @end deftypefn
+
+## Author: Kurt Hornik <address@hidden>
+## Adapted-By: jwe
+
+function retval = str2mat (varargin)
+  persistent warned = false;
+  if (! warned)
+    warned = true;
+    warning ("Octave:deprecated-function",
+             "str2mat is obsolete and will be removed from a future version of 
Octave; please use char instead.");
+  endif
+
+  retval = char (varargin{:});
+
+endfunction
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/strings/Makefile.in
--- a/scripts/strings/Makefile.in       Sun Nov 30 22:49:16 2008 +0100
+++ b/scripts/strings/Makefile.in       Tue Dec 02 21:22:30 2008 +0100
@@ -35,7 +35,7 @@
 
 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 str2mat.m \
+  lower.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
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/strings/str2mat.m
--- a/scripts/strings/str2mat.m Sun Nov 30 22:49:16 2008 +0100
+++ /dev/null   Thu Jan 01 00:00:00 1970 +0000
@@ -1,83 +0,0 @@
-## Copyright (C) 1996, 1998, 1999, 2000, 2002, 2004, 2005, 2006, 2007
-##               Kurt Hornik
-##
-## 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} {} str2mat (@var{s_1}, @dots{}, @var{s_n})
-## Return a matrix containing the strings @var{s_1}, @dots{}, @var{s_n} as
-## its rows.  Each string is padded with blanks in order to form a valid
-## matrix.
-##
-## This function is modelled after @sc{Matlab}.  In Octave, you can create
-## a matrix of strings by @address@hidden; @dots{}; @var{s_n}]} even if
-## the strings are not all the same length.
-## @end deftypefn
-
-## Author: Kurt Hornik <address@hidden>
-## Adapted-By: jwe
-
-function retval = str2mat (varargin)
-
-  if (nargin == 0)
-    print_usage ();
-  endif
-
-  nc = 0;
-  nr = 0;
-
-  nr = zeros (nargin, 1);
-  nc = zeros (nargin, 1);
-  for k = 1 : nargin
-    s = varargin{k};
-    if (! ischar (s))
-      s = char (s);
-    endif
-    [nr(k), nc(k)] = size (s);
-  endfor
-
-  tmp = find (nr == 0);
-
-  if (! isempty (tmp))
-    nr(tmp) = 1;
-  endif
-
-  retval_nr = sum (nr);
-  retval_nc = max (nc);
-
-  retval = char (ones (retval_nr, retval_nc) * toascii (" "));
-
-  row_offset = 0;
-  for k = 1 : nargin
-    s = varargin{k};
-    if (! ischar (s))
-      s = char (s);
-    endif
-    if (nc(k) > 0)
-      retval ((row_offset + 1) : (row_offset + nr(k)), 1:nc(k)) = s;
-    endif
-    row_offset = row_offset + nr(k);
-  endfor
-
-endfunction
-
-%!assert(strcmp (str2mat ("a", "bb", "ccc"), ["a  "; "bb "; "ccc"]));
-
-%!error str2mat ();
-
-%!assert(all (str2mat (1, 2, 3) == setstr ([1; 2; 3])));
-
diff -r f8ef2a2c44ce -r 16a19b3040e0 scripts/strings/strvcat.m
--- a/scripts/strings/strvcat.m Sun Nov 30 22:49:16 2008 +0100
+++ b/scripts/strings/strvcat.m Tue Dec 02 21:22:30 2008 +0100
@@ -21,8 +21,8 @@
 ## Return a matrix containing the strings (or cell-strings) 
 ## @var{s_1}, @dots{}, @var{s_n} as
 ## its rows.  Each string is padded with blanks in order to form a valid
-## matrix.  Unlike @var{str2mat}, empty strings are ignored.
-## @seealso{cstrcat, str2mat}
+## matrix.  Unlike @var{char}, empty strings are ignored.
+## @seealso{cstrcat, char}
 ## @end deftypefn
 
 ## Author: Kurt Hornik <address@hidden>
diff -r f8ef2a2c44ce -r 16a19b3040e0 src/ChangeLog
--- a/src/ChangeLog     Sun Nov 30 22:49:16 2008 +0100
+++ b/src/ChangeLog     Tue Dec 02 21:22:30 2008 +0100
@@ -1,3 +1,7 @@
+2008-12-02  Thorsten Meyer  <address@hidden>
+
+        * strfns.cc (Fchar): Add test from str2mat.m
+        
 2008-11-29  Thorsten Meyer  <address@hidden>
 
         * strfns.cc (Fchar), strfns.cc (Fischar), strfns.cc (Fstrncmp),
diff -r f8ef2a2c44ce -r 16a19b3040e0 src/strfns.cc
--- a/src/strfns.cc     Sun Nov 30 22:49:16 2008 +0100
+++ b/src/strfns.cc     Tue Dec 02 21:22:30 2008 +0100
@@ -149,6 +149,7 @@
 %!assert (all(char ({100, [], 100}) == ["d";" ";"d"]))
 %!assert (all(char ({100,{100, {""}}}) == ["d";"d";" "]))
 %!assert (all(char (["a";"be"], {"c", 100}) == ["a";"be";"c";"d"]))
+%!assert(strcmp (char ("a", "bb", "ccc"), ["a  "; "bb "; "ccc"]));
 */
 
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]