function out = eraseBetween(in,startStr,endStr, varargin)
%ERASEBETWEEN Remove segments from string elements.
%   S = ERASEBETWEEN(STR, START, END)
%   S = ERASEBETWEEN(..., 'Boundaries', B)
%
%   Limitations:
%   Pattern objects are not supported.
%
%   See also TALL/STRING.

%   Copyright 2016-2020 The MathWorks, Inc.

narginchk(3,5);

% First input must be tall string. Trailing arguments must not be.
tall.checkIsTall( upper(mfilename), 1, in );
in = tall.validateType(in, mfilename, {'string'}, 1);
tall.checkNotTall(upper(mfilename), 3, varargin{:});

% Pattern objects are not supported
matlab.bigdata.internal.util.errorIfPatternInput('tall', startStr, endStr, varargin{:});

% Treat all inputs element-wise, wrapping char arrays if used
startStr = wrapBoundaryInput(startStr);
endStr = wrapBoundaryInput(endStr);
out = elementfun(@(a,b,c) eraseBetween(a,b,c,varargin{:}), in, startStr, endStr);

% Output is same size and type as first input (can be cellstr or string)
out.Adaptor = in.Adaptor;

end
