Mercurial > hg > octave-lyh
annotate scripts/strings/blanks.m @ 17535:c12c688a35ed default tip lyh
Fix warnings
author | LYH <lyh.kernel@gmail.com> |
---|---|
date | Fri, 27 Sep 2013 17:43:27 +0800 |
parents | cbcaf5602469 |
children |
rev | line source |
---|---|
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
13179
diff
changeset
|
1 ## Copyright (C) 1996-2012 Kurt Hornik |
2325 | 2 ## |
2313 | 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 | |
7016 | 7 ## the Free Software Foundation; either version 3 of the License, or (at |
8 ## your option) any later version. | |
2313 | 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 | |
7016 | 16 ## along with Octave; see the file COPYING. If not, see |
17 ## <http://www.gnu.org/licenses/>. | |
2268 | 18 |
3361 | 19 ## -*- texinfo -*- |
20 ## @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
|
21 ## 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
|
22 ## |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
23 ## @example |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
24 ## @group |
13179
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
25 ## blanks (10); |
14402
cbcaf5602469
doc: Make spacing nicer for Strings chapter of manual.
Rik <octave@nomad.inbox5.com>
parents:
14363
diff
changeset
|
26 ## whos ans |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
27 ## @result{} |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
28 ## Attr Name Size Bytes Class |
11587
c792872f8942
all script files: untabify and strip trailing whitespace
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
29 ## ==== ==== ==== ===== ===== |
8442
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
30 ## 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
|
31 ## @end group |
502e58a0d44f
Fix docstrings, add examples, references and tests to string functions
Thorsten Meyer <thorsten.meyier@gmx.de>
parents:
7411
diff
changeset
|
32 ## @end example |
6138 | 33 ## @seealso{repmat} |
3361 | 34 ## @end deftypefn |
2311 | 35 |
5428 | 36 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
2355 | 37 ## Adapted-By: jwe |
2314 | 38 |
2268 | 39 function s = blanks (n) |
2325 | 40 |
2268 | 41 if (nargin != 1) |
6046 | 42 print_usage (); |
13179
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
43 elseif (! (isscalar (n) && n == fix (n) && n >= 0)) |
11472
1740012184f9
Use uppercase for variable names in error() strings to match Info documentation. Only m-files done.
Rik <octave@nomad.inbox5.com>
parents:
8920
diff
changeset
|
44 error ("blanks: N must be a non-negative integer"); |
2268 | 45 endif |
2325 | 46 |
6387 | 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) = " "; | |
6138 | 50 |
2268 | 51 endfunction |
6138 | 52 |
13179
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
53 |
6138 | 54 ## There really isn't that much to test here |
14363
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
55 %!assert (blanks (0), "") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
56 %!assert (blanks (5), " ") |
f3d52523cde1
Use Octave coding conventions in all m-file %!test blocks
Rik <octave@nomad.inbox5.com>
parents:
14138
diff
changeset
|
57 %!assert (blanks (10), " ") |
7411 | 58 |
13179
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
59 %% Test input validation |
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
60 %!error blanks () |
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
61 %!error blanks (1, 2) |
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
62 %!error blanks (ones (2)) |
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
63 %!error blanks (2.1) |
8c4a2c2cc2b0
blanks.m: Validate input is non-negative.
Rik <octave@nomad.inbox5.com>
parents:
11587
diff
changeset
|
64 %!error blanks (-2) |
7411 | 65 |