changeset 6138:c5874b47d571

[project @ 2006-11-03 18:26:11 by jwe]
author jwe
date Fri, 03 Nov 2006 18:28:37 +0000
parents 4fb3f3e3d6bb
children 4da9f63d5237
files scripts/ChangeLog scripts/strings/blanks.m scripts/strings/strcat.m src/ChangeLog src/help.cc
diffstat 5 files changed, 44 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/scripts/ChangeLog	Fri Nov 03 18:19:11 2006 +0000
+++ b/scripts/ChangeLog	Fri Nov 03 18:28:37 2006 +0000
@@ -1,3 +1,7 @@
+2006-11-03  Bill Denney  <denney@seas.upenn.edu>
+
+	* scripts/blanks.m, scripts/strcat.m: Simplify.  Add tests.
+
 2006-11-01  Bill Denney  <denney@seas.upenn.edu>
 
 	* general/__isequal__.m: Test size and class more consistently.
--- a/scripts/strings/blanks.m	Fri Nov 03 18:19:11 2006 +0000
+++ b/scripts/strings/blanks.m	Fri Nov 03 18:28:37 2006 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 1996 Kurt Hornik
+## Copyright (C) 1996, 2006 Kurt Hornik
 ##
 ## This file is part of Octave.
 ##
@@ -20,6 +20,7 @@
 ## -*- texinfo -*-
 ## @deftypefn {Function File} {} blanks (@var{n})
 ## Return a string of @var{n} blanks.
+## @seealso{repmat}
 ## @end deftypefn
 
 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
@@ -29,12 +30,15 @@
 
   if (nargin != 1)
     print_usage ();
-  endif
-
-  if (isscalar (n) && n == round (n))
-    s = char (ones (1, n) * toascii (" "));
-  else
+  elseif (! (isscalar (n) && n == round (n)))
     error ("blanks: n must be a non-negative integer");
   endif
 
+  s(1,1:n) = " ";
+
 endfunction
+
+## There really isn't that much to test here
+%!assert(blanks (0), "")
+%!assert(blanks (5), "     ")
+%!assert(blanks (10), "          ")
--- a/scripts/strings/strcat.m	Fri Nov 03 18:19:11 2006 +0000
+++ b/scripts/strings/strcat.m	Fri Nov 03 18:28:37 2006 +0000
@@ -1,4 +1,4 @@
-## Copyright (C) 1996, 1997 John W. Eaton
+## Copyright (C) 1996, 1997, 2006 John W. Eaton
 ##
 ## This file is part of Octave.
 ##
@@ -33,28 +33,20 @@
 
 ## Author: jwe
 
-function st = strcat (s, varargin)
+function st = strcat (varargin)
 
-  if (nargin > 0)
-    if (ischar (s))
-      tmpst = s;
-    else
-      error ("strcat: all arguments must be strings");
-    endif
-    n = nargin - 1;
-    k = 1;
-    while (n--)
-      tmp = varargin{k++};
-      if (ischar (tmp))
-	tmpst = [tmpst, tmp];
-      else
-	error ("strcat: all arguments must be strings");
-      endif
-    endwhile
-  else
+  if (nargin < 1)
     print_usage ();
+  elseif (! iscellstr (varargin))
+    error ("strcat: all arguments must be strings");
   endif
 
-  st = tmpst;
+  st = [varargin{:}];
 
 endfunction
+
+## test the dimensionality
+## 1d
+%!assert(strcat("ab ", "ab "), "ab ab ")
+## 2d
+%!assert(strcat(["ab ";"cde"], ["ab ";"cde"]), ["ab ab ";"cdecde"])
--- a/src/ChangeLog	Fri Nov 03 18:19:11 2006 +0000
+++ b/src/ChangeLog	Fri Nov 03 18:28:37 2006 +0000
@@ -1,3 +1,7 @@
+2006-11-03  Bill Denney  <denney@seas.upenn.edu>
+
+	* help.cc (keywords): Document try and unwind_protect.
+
 2006-11-03  John W. Eaton  <jwe@octave.org>
 
 	* Makefile.in (DLL_CXXDEFS): Rename from XTRA_CXXDEFS.
--- a/src/help.cc	Fri Nov 03 18:19:11 2006 +0000
+++ b/src/help.cc	Fri Nov 03 18:28:37 2006 +0000
@@ -452,7 +452,12 @@
     "-*- texinfo -*-\n\
 @deffn Keyword try\n\
 Begin a try-catch block.\n\
-@seealso{catch}\n\
+\n\
+If an error occurs within a try block, then the catch code will be run and\n\
+execution will proceed after the catch block (though it is often\n\
+recommended to use the lasterr function to re-throw the error after cleanup\n\
+is completed).\n\
+@seealso{catch,unwind_protect}\n\
 @end deffn", }, 
 
   { "until",
@@ -466,7 +471,14 @@
     "-*- texinfo -*-\n\
 @deffn Keyword unwind_protect\n\
 Begin an unwind_protect block.\n\
-@seealso{unwind_protect_cleanup}\n\
+\n\
+If an error occurs within the first part of an unwind_protect block\n\
+the commands within the unwind_protect_cleanup block are executed before\n\
+the error is thrown.  If an error is not thrown, then the\n\
+unwind_protect_cleanup block is still executed (in other words, the\n\
+unwind_protect_cleanup will be run with or without an error in the\n\
+unwind_protect block).\n\
+@seealso{unwind_protect_cleanup,try}\n\
 @end deffn", }, 
 
   { "unwind_protect_cleanup",