function encoding = getEncoding(aCGTLine)
% getEncoding returns the encoding specified through a line in the CGT file
% with the 'encodingIn' tag, e.g.:
%   <encodingIn="UTF-8">
% where, 'UTF-8' is returned.
%
% If the line is not valid, an empty char array is returned.
%
% Copyright 2022 The MathWorks, Inc.

    if (coder.isEncodingTag(aCGTLine))

        % If user specifies the CGT file encoding we can then properly read in the file and
        % escape unmapped characters so they are rendered correctly in the report.
        encoding = cell2mat(regexprep(regexp(aCGTLine, '".*"', 'match'),'"',''));
        if isempty (encoding)
            % mimic fopen's behavior (MATLAB default character encoding)
            encoding = '';
        end
    else
        encoding = '';
    end

end
