7017
|
1 ## Copyright (C) 1996, 2007 Kurt Hornik |
6975
|
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 |
7016
|
7 ## the Free Software Foundation; either version 3 of the License, or (at |
|
8 ## your option) any later version. |
6975
|
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/>. |
6975
|
18 |
|
19 ## -*- texinfo -*- @deftypefn {Function File} {} deblank (@var{s}) |
|
20 ## Remove leading and trailing blanks and nulls from @var{s}. If |
|
21 ## @var{s} is a matrix, @var{deblank} trims each row to the length of |
|
22 ## longest string. If @var{s} is a cell array, operate recursively on |
|
23 ## each element of the cell array. @end deftypefn |
|
24 |
|
25 ## Author: John Swensen <jpswensen@jhu.edu> |
|
26 |
|
27 ## This function was derived from deblank. |
|
28 |
|
29 function s = strtrim (s) |
|
30 |
|
31 if (nargin != 1) |
|
32 print_usage (); |
|
33 endif |
|
34 |
|
35 if (ischar (s)) |
|
36 |
|
37 k = find (! isspace (s) & s != "\0"); |
|
38 if (isempty (s) || isempty (k)) |
|
39 s = ""; |
|
40 else |
|
41 s = s(:,ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); |
|
42 endif |
|
43 |
|
44 elseif (iscell(s)) |
|
45 |
|
46 s = cellfun (@strtrim, s, "UniformOutput", false); |
|
47 |
|
48 else |
|
49 error ("strtrim: expecting string argument"); |
|
50 endif |
|
51 |
|
52 endfunction |