1 function resu = df_check_char_array(x, nelem, required)
3 %# auxiliary function: pad a char array to some width
5 %% Copyright (C) 2009-2012 Pascal Dupuis <Pascal.Dupuis@uclouvain.be>
7 %% This file is part of Octave.
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.
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
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.
26 %# $Id: df_check_char_array.m 9585 2012-02-05 15:32:46Z cdemills $
29 if 2 == nargin, required = [nelem 1]; endif
31 if nelem < required(1),
32 error("Too many elements to assign");
35 %# a zero-length element is still considered as a space by char
36 if isempty(x), x = ' '; endif
38 if size(x, 1) < max(required(1), nelem)
40 dummy = repmat(' ', nelem-size(x, 1), 1);
41 resu = char(x, dummy);
46 if size(resu, 2) < required(2),
48 dummy = repmat(' ', nelem, required(2)-size(resu, 2));
49 resu = horzcat(resu, dummy);