function varargout = convertCharsToStrings(varargin)
%MATLAB Code Generation Library Function

%   Copyright 2017 The MathWorks, Inc.
%#codegen
coder.internal.assert(nargin == nargout, 'Coder:toolbox:NarginNargoutMismatch');
for k = coder.unroll(1:nargin)
    varargout{k} = convertCharOrCellstr(varargin{k});
end

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

function c = convertCharOrCellstr(t)
if ischar(t)
    c = string(linearizeChar(t));
elseif iscellstr(t) %#ok<ISCLSTR>
    tt = cell(size(t));
    for k = 1:numel(t)
        tt{k} = linearizeChar(t{k});
    end
    c = string(tt);
else
    c = t;
end

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

function tl = linearizeChar(t)
% Flatten a char array to a row in all cases except for empties
if isempty(t) || isrow(t)
    tl = t;
else
    tl = t(:)';
end

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