2313
|
1 ## Copyright (C) 1996 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 |
|
7 ## the Free Software Foundation; either version 2, or (at your option) |
|
8 ## 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, write to the Free |
5307
|
17 ## Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
18 ## 02110-1301, USA. |
2268
|
19 |
3361
|
20 ## -*- texinfo -*- |
|
21 ## @deftypefn {Function File} {} deblank (@var{s}) |
5462
|
22 ## Remove trailing blanks and nulls from @var{s}. If @var{s} |
|
23 ## is a matrix, @var{deblank} trims each row to the length of longest |
|
24 ## string. If @var{s} is a cell array, operate recursively on each |
|
25 ## element of the cell array. |
3361
|
26 ## @end deftypefn |
2311
|
27 |
5428
|
28 ## Author: Kurt Hornik <Kurt.Hornik@wu-wien.ac.at> |
2355
|
29 ## Adapted-By: jwe |
2314
|
30 |
5462
|
31 function s = deblank (s) |
2325
|
32 |
2268
|
33 if (nargin != 1) |
6046
|
34 print_usage (); |
2268
|
35 endif |
2325
|
36 |
5443
|
37 if (ischar (s)) |
2268
|
38 |
5093
|
39 k = find (! isspace (s) & s != "\0"); |
3894
|
40 if (isempty (s) || isempty (k)) |
5462
|
41 s = ""; |
2268
|
42 else |
5462
|
43 s = s(:,1:ceil (max (k) / rows (s))); |
2268
|
44 endif |
|
45 |
5462
|
46 elseif (iscell(s)) |
|
47 |
6023
|
48 s = cellfun (@deblank, s, "UniformOutput", false); |
5462
|
49 |
2268
|
50 else |
|
51 error ("deblank: expecting string argument"); |
|
52 endif |
|
53 |
|
54 endfunction |