]> Creatis software - CreaPhase.git/blob - octave_packages/m/strings/blanks.m
update packages
[CreaPhase.git] / octave_packages / m / strings / blanks.m
1 ## Copyright (C) 1996-2012 Kurt Hornik
2 ##
3 ## This file is part of Octave.
4 ##
5 ## Octave is free software; you can redistribute it and/or modify it
6 ## under the terms of the GNU General Public License as published by
7 ## the Free Software Foundation; either version 3 of the License, or (at
8 ## your option) any later version.
9 ##
10 ## Octave is distributed in the hope that it will be useful, but
11 ## WITHOUT ANY WARRANTY; without even the implied warranty of
12 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 ## General Public License for more details.
14 ##
15 ## You should have received a copy of the GNU General Public License
16 ## along with Octave; see the file COPYING.  If not, see
17 ## <http://www.gnu.org/licenses/>.
18
19 ## -*- texinfo -*-
20 ## @deftypefn {Function File} {} blanks (@var{n})
21 ## Return a string of @var{n} blanks, for example:
22 ##
23 ## @example
24 ## @group
25 ## blanks (10);
26 ## whos ans;
27 ##      @result{}
28 ##       Attr Name        Size                     Bytes  Class
29 ##       ==== ====        ====                     =====  =====
30 ##            ans         1x10                        10  char
31 ## @end group
32 ## @end example
33 ## @seealso{repmat}
34 ## @end deftypefn
35
36 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at>
37 ## Adapted-By: jwe
38
39 function s = blanks (n)
40
41   if (nargin != 1)
42     print_usage ();
43   elseif (! (isscalar (n) && n == fix (n) && n >= 0))
44     error ("blanks: N must be a non-negative integer");
45   endif
46
47   ## If 1:n is empty, the following expression will create an empty
48   ## character string.  Otherwise, it will create a row vector.
49   s(1:n) = " ";
50
51 endfunction
52
53
54 ## There really isn't that much to test here
55 %!assert(blanks (0), "")
56 %!assert(blanks (5), "     ")
57 %!assert(blanks (10), "          ")
58
59 %% Test input validation
60 %!error blanks ()
61 %!error blanks (1, 2)
62 %!error blanks (ones (2))
63 %!error blanks (2.1)
64 %!error blanks (-2)
65