function len = strlength(s)
%MATLAB Code Generation Library Function

%   Copyright 2016 The MathWorks, Inc.
%#codegen
coder.inline('always');
narginchk(1, 1);
len = double(intstrlen(s));

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

function len = intstrlen(s)
if iscell(s)
    len = zeros(size(s),coder.internal.indexIntClass());
    ns = coder.internal.indexInt(numel(s));
    for idx = 1:ns
        len(idx) = charlength(s{idx});
    end
else
    len = charlength(s);
end

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

function clen = charlength(s)
if ischar(s)
    coder.internal.assert(isempty(s) || isrow(s), ...
        'Coder:toolbox:MustBeCharCellArrayOrString',1);
    clen = coder.internal.indexInt(numel(s));
else
    coder.internal.assert(coder.internal.isAmbiguousTypes, ...
        'Coder:toolbox:MustBeCharCellArrayOrString',1);
    clen = coder.ignoreConst(0);
end

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