Mercurial > hg > octave-lyh
annotate scripts/strings/blanks.m @ 8442:502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
author | Thorsten Meyer <thorsten.meyier@gmx.de> |
---|---|
date | Mon, 05 Jan 2009 08:11:03 +0100 |
parents | 83a8781b529d |
children | eb63fbe60fab |
rev | line source |
---|---|
7017 | 1 ## Copyright (C) 1996, 1997, 1999, 2002, 2003, 2005, 2006, 2007 |
2 ## Kurt Hornik | |
2325 | 3 ## |
2313 | 4 ## This file is part of Octave. |
5 ## | |
6 ## Octave is free software; you can redistribute it and/or modify it | |
7 ## under the terms of the GNU General Public License as published by | |
7016 | 8 ## the Free Software Foundation; either version 3 of the License, or (at |
9 ## your option) any later version. | |
2313 | 10 ## |
11 ## Octave is distributed in the hope that it will be useful, but | |
12 ## WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 ## General Public License for more details. | |
15 ## | |
16 ## You should have received a copy of the GNU General Public License | |
7016 | 17 ## along with Octave; see the file COPYING. If not, see |
18 ## <http://www.gnu.org/licenses/>. | |
2268 | 19 |
3361 | 20 ## -*- texinfo -*- |
21 ## @deftypefn {Function File} {} blanks (@var{n}) | |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
22 ## Return a string of @var{n} blanks, for example: |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
23 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
24 ## @example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
25 ## @group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
26 ## blanks(10); |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
27 ## whos ans; |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
28 ## @result{} |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
29 ## Attr Name Size Bytes Class |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
30 ## ==== ==== ==== ===== ===== |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
31 ## ans 1x10 10 char |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
32 ## @end group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
33 ## @end example |
6138 | 34 ## @seealso{repmat} |
3361 | 35 ## @end deftypefn |
2311 | 36 |
5428 | 37 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
2355 | 38 ## Adapted-By: jwe |
2314 | 39 |
2268 | 40 function s = blanks (n) |
2325 | 41 |
2268 | 42 if (nargin != 1) |
6046 | 43 print_usage (); |
6138 | 44 elseif (! (isscalar (n) && n == round (n))) |
3081 | 45 error ("blanks: n must be a non-negative integer"); |
2268 | 46 endif |
2325 | 47 |
6387 | 48 ## If 1:n is empty, the following expression will create an empty |
49 ## character string. Otherwise, it will create a row vector. | |
50 s(1:n) = " "; | |
6138 | 51 |
2268 | 52 endfunction |
6138 | 53 |
54 ## There really isn't that much to test here | |
55 %!assert(blanks (0), "") | |
56 %!assert(blanks (5), " ") | |
57 %!assert(blanks (10), " ") | |
7411 | 58 |
59 %!assert(strcmp (blanks (3), " ")); | |
60 | |
61 %!error blanks (); | |
62 | |
63 %!error blanks (1, 2); | |
64 |