function s = insertBefore(str, pos, text)
%MATLAB Code Generation Library Function
%
% Limitations:
%
%   1. str and text must be one of: string scalar, character row vector, scalar
%   cellstr
%   2. pos must be numeric or 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);
sinserted = st.insertBefore(pos, text);

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