]> Creatis software - CreaPhase.git/blob - octave_packages/dataframe-0.9.1/@dataframe/private/df_check_char_array.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / dataframe-0.9.1 / @dataframe / private / df_check_char_array.m
1 function resu = df_check_char_array(x, nelem, required)
2
3   %# auxiliary function: pad a char array to some width
4
5   %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
6   %%
7   %% This file is part of Octave.
8   %%
9   %% Octave is free software; you can redistribute it and/or
10   %% modify it under the terms of the GNU General Public
11   %% License as published by the Free Software Foundation;
12   %% either version 2, or (at your option) any later version.
13   %%
14   %% Octave is distributed in the hope that it will be useful,
15   %% but WITHOUT ANY WARRANTY; without even the implied
16   %% warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17   %% PURPOSE.  See the GNU General Public License for more
18   %% details.
19   %%
20   %% You should have received a copy of the GNU General Public
21   %% License along with Octave; see the file COPYING.  If not,
22   %% write to the Free Software Foundation, 51 Franklin Street -
23   %% Fifth Floor, Boston, MA 02110-1301, USA.
24   
25   %#
26   %# $Id: df_check_char_array.m 9585 2012-02-05 15:32:46Z cdemills $
27   %#
28   
29   if 2 == nargin, required = [nelem 1]; endif
30
31   if nelem < required(1),
32     error("Too many elements to assign");
33   endif
34
35   %# a zero-length element is still considered as a space by char
36   if isempty(x), x = ' '; endif 
37
38   if size(x, 1) < max(required(1), nelem)
39     %# pad vertically
40     dummy = repmat(' ', nelem-size(x, 1), 1);
41     resu = char(x, dummy);
42   else
43     resu = x;
44   endif
45       
46   if size(resu, 2) < required(2),
47     %# pad horizontally
48     dummy = repmat(' ', nelem, required(2)-size(resu, 2));
49     resu = horzcat(resu, dummy);
50   endif
51
52 endfunction