function s = replace(str, old, new)
%MATLAB Code Generation Library Function
%
% Limitations:
%
%   1. str, old, and new must be one of: string scalar, character row vector,
%   scalar cellstr

%   Copyright 2017 The MathWorks, Inc.
%#codegen

narginchk(3, 3);
if ~isstring(str) && ~ischar(str) && coder.internal.isAmbiguousTypes
    s = coder.ignoreConst(str);
    return
end
coder.internal.assert(isTextStrict(str), 'Coder:toolbox:MustBeCharOrString', 1);

st = string(str);
sreplaced = st.replace(old, new);

if ischar(str)
    s = char(sreplaced);
elseif iscell(str)
    s = cellstr(sreplaced);
else
    s = sreplaced;
end
