function rev = reverse(s)
%MATLAB Code Generation Library Function
%
% Limitations:
%
%   1. s must be one of: string scalar, character row vector, cellstr (cell
%   array with multiple character row vectors).

%   Copyright 2017 The MathWorks, Inc.
%#codegen
narginchk(1, 1);
if ~isstring(s) && ~ischar(s) && coder.internal.isAmbiguousTypes
    rev = coder.ignoreConst(s);
    return
end
coder.internal.assert(isTextStrict(s), 'Coder:toolbox:MustBeCharCellArrayOrString', 1);

if iscell(s)
    rev = coder.nullcopy(cell(size(s)));
    for idx = 1:numel(s)
        rev{idx} = charReverse(s{idx});
    end
else % Note: the string case is automatically handled by the string class
    rev = charReverse(s);
end

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

function crev = charReverse(s)

coder.internal.assert(ischar(s) && (isempty(s) || isrow(s)), ...
                      'Coder:toolbox:MustBeCharCellArrayOrString', 1);
crev = fliplr(s);

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