/usr/share/psychtoolbox-3/PsychOneliners/StrPad.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | function str = StrPad(in,len,char)
% str = StrPad(in,length,padchar)
% (pre)pads IN with CHAR to sepcified length LEN. If inputs IN or PADCHAR
% are numerical, they will be converted to to string. If input is too long,
% it is truncated from the start to specified length.
%
% DN 2007
if isnumeric(in) && length(in)==1 && in==round(in)
% convert to string
in = num2str(in);
end
if isnumeric(char) && length(char)==1
% convert to string
char = num2str(char);
end
if ischar(in)
% check that we have a string
inlen = length(in);
if inlen > len
% truncate
b = inlen - len; % string is b characters too long
str = in(b+1:end);
elseif inlen == len
% string is right length already
str = in;
else
% pre-pad
b = len - inlen; % string is b characters too short
str = [repmat(char,1,b) in];
end
else
error('input must be char or scalar integer');
end
|