function y = deblank(x)
%MATLAB Code Generation Library Function

%   Limitations:
%   1. Only supports 'char' inputs, cell array not supported.
%   2. Input values must be in the range 0-127.

%   Copyright 1984-2015 The MathWorks, Inc.
%#codegen

eml_invariant(nargin > 0, ...
    'MATLAB:minrhs');
eml_invariant(~iscell(x), 'Coder:toolbox:CellArraysNotSupported', mfilename);
eml_invariant(ischar(x), ...
    'Coder:toolbox:unsupportedClass',mfilename,class(x));
coder.internal.prefer_const(x);
eml_invariant(ismatrix(x), ...
    'MATLAB:deblank:TooManyDimensions');
ncols = deblank_ncols(x);
y = x(:,1:ncols);

%--------------------------------------------------------------------------

function n = deblank_ncols(x)
coder.internal.prefer_const(x);
n = coder.internal.indexInt(size(x,2));
while n > 0 && allwspace(x,n)
    n = n - 1;
end

%--------------------------------------------------------------------------

function p = allwspace(x,col)
coder.internal.prefer_const(x);
coder.inline('always');
for i = 1:size(x,1)
    if x(i,col) ~= 0 && ~isstrprop(x(i,col),'wspace')
        p = false;
        return
    end
end
p = true;

%--------------------------------------------------------------------------
