Mercurial > hg > octave-nkf
annotate scripts/strings/strtrim.m @ 7926:d74f996e005d
__magick_read__.cc: configuration and style fixes
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 14 Jul 2008 16:00:09 -0400 |
parents | 693ac94c2854 |
children | 502e58a0d44f |
rev | line source |
---|---|
7346 | 1 ## Copyright (C) 1996, 2007, 2008 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 |
7346 | 19 ## -*- texinfo -*- |
7666
693ac94c2854
Fixed minor bugs in help texts of [x|y|z]lim and strtrim
sh@sh-laptop
parents:
7346
diff
changeset
|
20 ## @deftypefn {Function File} {} strtrim (@var{s}) |
6975 | 21 ## Remove leading and trailing blanks and nulls from @var{s}. If |
7666
693ac94c2854
Fixed minor bugs in help texts of [x|y|z]lim and strtrim
sh@sh-laptop
parents:
7346
diff
changeset
|
22 ## @var{s} is a matrix, @var{strtrim} trims each row to the length of |
6975 | 23 ## longest string. If @var{s} is a cell array, operate recursively on |
7346 | 24 ## each element of the cell array. |
25 ## @end deftypefn | |
6975 | 26 |
27 ## Author: John Swensen <jpswensen@jhu.edu> | |
28 | |
29 ## This function was derived from deblank. | |
30 | |
31 function s = strtrim (s) | |
32 | |
33 if (nargin != 1) | |
34 print_usage (); | |
35 endif | |
36 | |
37 if (ischar (s)) | |
38 | |
39 k = find (! isspace (s) & s != "\0"); | |
40 if (isempty (s) || isempty (k)) | |
41 s = ""; | |
42 else | |
43 s = s(:,ceil (min (k) / rows (s)):ceil (max (k) / rows (s))); | |
44 endif | |
45 | |
46 elseif (iscell(s)) | |
47 | |
48 s = cellfun (@strtrim, s, "UniformOutput", false); | |
49 | |
50 else | |
51 error ("strtrim: expecting string argument"); | |
52 endif | |
53 | |
54 endfunction |