function varargout = convertPVPairsToChars(varargin)
%convertPVPairsToChars Convert PV pairs from string to char
%   varargout = convertPVPairsToChars(varargin) converts string PV pairs
%   to chars. It knows not to convert the V side for properties that
%   might legitimately contain string objects, i.e. UserData.

% Copyright 2018 The MathWorks, Inc.

if mod(nargin, 2) == 0
    % Even number of arguments, proceed.
    args = varargin;
    [args{1:2:end}] = convertStringsToChars(args{1:2:end});
    propNames = args(1:2:end);
    if iscellstr(propNames)
        propValues = args(2:2:end);
        % Definitely got P-V pairs
        isPreciousProperty = ismember(propNames, {'UserData'});
        [propValues{~isPreciousProperty}] = convertStringsToChars(propValues{~isPreciousProperty});
        args = [propNames(:)'; propValues(:)'];
        varargout = args(:)';
        return
    end
end
% Not P-V pairs, revert to converting all.
[varargout{1:nargin}] = convertStringsToChars(varargin{:});
end
