function data = ReplaceNamedHTMLChars(data)
% This will replace named HTML entities with the ASCII-encoded characters.
% Common symbols will be replaced with strrep. After that, a generic search should turn up all
% entities listed here: https://html.spec.whatwg.org/entities.json.
% To avoid clashes with HTML parsing, the less-than and greater-than symbols are replaced by the
% numeric encoding.
%
%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%
%|                                                                         |%
%|  Version: 0.0.1 [unpublished alpha]                                     |%
%|  Date:    2023-03-17                                                    |%
%|  Author:  H.J. Wisselink                                                |%
%|  Licence: CC by-nc-sa 4.0 ( creativecommons.org/licenses/by-nc-sa/4.0 ) |%
%|  Email = 'h_j_wisselink*alumnus_utwente_nl';                            |%
%|  Real_email = regexprep(Email,{'*','_'},{'@','.'})                      |%
%|                                                                         |%
%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%

% If there are no entities, skip the rest of this function.
if isempty(regexp(data,'&[a-zA-Z]+[0-9]*;','once')),return,end

% First replace common symbols.
data = strrep(data,'&nbsp;','&#160;');
data = strrep(data,'&quot;','''');
data = strrep(data,'&lt;','&#60;');
data = strrep(data,'&gt;','&#62;');
data = strrep(data,'&rdquo;','&#8221;');
data = strrep(data,'&rsquo;','&#8217;');
data = strrep(data,'&lsquo;','&#8216;');

% If there are no entities, skip the rest of this function.
if isempty(regexp(data,'&[a-zA-Z]+[0-9]*;','once')),return,end

% Next replace the common lowercase consonants.
data = strrep(data,'&agrave;','&#224;');
data = strrep(data,'&aacute;','&#225;');
data = strrep(data,'&acirc;' ,'&#226;');
data = strrep(data,'&auml;'  ,'&#228;');
data = strrep(data,'&egrave;','&#232;');
data = strrep(data,'&eacute;','&#233;');
data = strrep(data,'&ecirc;' ,'&#234;');
data = strrep(data,'&euml;'  ,'&#235;');
data = strrep(data,'&igrave;','&#236;');
data = strrep(data,'&iacute;','&#237;');
data = strrep(data,'&icirc;' ,'&#238;');
data = strrep(data,'&iuml;'  ,'&#239;');
data = strrep(data,'&ograve;','&#242;');
data = strrep(data,'&oacute;','&#243;');
data = strrep(data,'&ocirc;' ,'&#244;');
data = strrep(data,'&ouml;'  ,'&#246;');
data = strrep(data,'&ugrave;','&#249;');
data = strrep(data,'&uacute;','&#250;');
data = strrep(data,'&ucirc;' ,'&#251;');
data = strrep(data,'&uuml;'  ,'&#252;');

% Now scan for remaining symbols.
tokens = regexp_outkeys(data,'&[a-zA-Z]+[0-9]*;','match');
if numel(tokens)>0
    dict = GetEntityList;
    L = ismember(dict(:,1),tokens);
    for k=find(L).'
        data = strrep(data,dict{k,1},dict{k,2});
    end
end
end
function dict=GetEntityList
persistent dict_
fn = fullfile(GetWritableFolder,'HTML_entity_list.json');
if ~exist(fn,'file')
    % Load the latest capture to the Wayback Machine from the spec file.
    data = readfile('http://web.archive.org/web/2id_/https://html.spec.whatwg.org/entities.json');
    % remove trailing semicolons and make the list unique.
    data = unique(strrep(data,';"','"'));
    % Remove the lines with the opening and closing braces, as well as the trailing empty line.
    data(cellfun('prodofsize',data)<10) = [];

    dict = cell(numel(data),2);
    for n=1:numel(data)
        entity = regexp_outkeys(data{n},'"&([^"]*)','tokens');
        entity = entity{1}{1};
        description = regexp_outkeys(data{n},'{[^}]*}','match');
        description = JSON(description{1});
        dict{n,1} = ['&' entity ';'];
        dict{n,2} = sprintf('&#%d;',description.codepoints);
    end

    % Store parsed results to file in a JSON format.
    tmp = dict.';
    tmp = sprintf('["%s","%s"],\n',tmp{:});
    tmp = ['[' tmp(1:(end-2)) ']'];
    fid = fopen(fn,'w');
    fprintf(fid,'%s',tmp);
    fclose(fid);

    % No need to read back the file and parse it.
    dict_ = dict;
    return
end
if isempty(dict_)
    % Read persistent from file.
    dict_ = JSON(fileread(fn));
end
dict = dict_;
end
function v000=ParseValue(v001),persistent v002,if isempty(v002),v002=num2cell('-0123456789');
end,if numel(v001.str)==0,v001.str=' ';end,v001.depth=v001.depth+1;if ...
v001.depth>v001.opts.MaxRecursionDepth,...
throw_error('Recursion limit reached, exiting to avoid crashes.','Recursion'),end,switch ...
v001.str(1),case'{';v000=ParseObject(v001);case'[';v000=ParseArray(v001);case v002;v000=...
ParseNumber(v001.str,v001.opts.EnforceValidNumber);case'"';v000=ParseString(v001.str);if ...
numel(v000)==0,v000='';end;case't';if~strcmp(v001.str,'true');v003=...
'Unexpected literal, expected ''true''.';v004='Literal';throw_error(v003,v004);end;v000=true;
case'f';if~strcmp(v001.str,'false');v003='Unexpected literal, expected ''false''.';v004=...
'Literal';throw_error(v003,v004);end;v000=false;case'n';if~strcmp(v001.str,'null');v003=...
'Unexpected literal, expected ''null''.';v004='Literal';throw_error(v003,v004);end;v000=[];
otherwise;v003='Unexpected character, expected a brace, bracket, number, string, or literal.';
v004='Literal';throw_error(v003,v004);end;end
function v000=ParseObject(v001),v002=find(v001.braces==-v001.braces(1));if numel(v002)~=...
1||v002~=numel(v001.str)||~strcmp(v001.str([1 end]),'{}'),v003='Unexpected end of object.';v004=...
'Object';throw_error(v003,v004),end,v000=struct;if v002==2,return,end,v005=index(v001,[2 ...
numel(v001.str)-1]);v006=find(cumsum(v005.braces)==0&v005.s_tokens==',');v006=[0 v006 ...
numel(v005.str)+1];v006=[v006(1:(end-1))+1;v006(2:end)-1];v007=cell(size(v006));for v008=...
1:size(v006,2),v009=index(v005,v006(:,v008));v010=v009.s_tokens==':';if~any(v010),...
throw_error('No colon found in object definition.','Object'),end,v002=find(v010);v002=v002(1);
try v007{1,v008}=ParseString(v009.str(1:(v002-1)));catch,...
throw_error('Invalid key in object definition.','Object'),end,try v007{2,v008}=...
ParseValue(index(v009,v002+1));catch,throw_error('Invalid value in object definition.',...
'Object'),end,if isa(v007{2,v008},'cell'),v007{2,v008}=v007(2,v008);end,end,persistent v011 ...
v012,if isempty(v011),v013=char([9 10 11 12 13 32]);v011=['[' v013 ']+([^' v013 '])'];v012=...
strcmp('fooBar',regexprep('foo bar',v011,'${upper($1)}'));end,for v008=1:size(v007,2),v014=...
v007{1,v008};if v012,v014=regexprep(v014,v011,'${upper($1)}');else,[v015,v016]=regexp(v014,...
v011);if~isempty(v015),v014(v016)=upper(v014(v016));v010=zeros(size(v014));v010(v015)=1;
v010(v016)=-1;v010=logical(cumsum(v010));v014(v010)='';end,end,v014=regexprep(v014,'\s','');
v017=find(double(v014)==0);if~isempty(v017),v014(v017(1):end)='';end,v014=regexprep(v014,...
'[^0-9a-zA-Z_]','_');if isempty(v014)||any(v014(1)=='_0123456789'),v014=['x' v014];end,v018=...
v014;v019=0;while ismember(v014,v007(1,1:(v008-1))),v019=v019+1;v014=sprintf('%s_%d',v018,v019);
end,v007{1,v008}=v014;end,v000=struct(v007{:});end
function v000=bsxfun_plus(v001,v002),persistent v003,if isempty(v003),v003=...
double(hasFeature('ImplicitExpansion')) + double(hasFeature('bsxfun'));end,if v003==2,v000=...
v001+v002;elseif v003==1,v000=bsxfun(@plus,v001,v002);else,v004=size(v001);v005=size(v002);if ...
min([v004 v005])==0,v004(v004==0)=inf;v005(v005==0)=inf;v006=max(v004,v005);v006(isinf(v006))=0;
v000=feval(str2func(class(v001)),zeros(v006));return,end,v001=repmat(v001,max(1,v005./v004));
v002=repmat(v002,max(1,v004./v005));v000=v001+v002;end,end
function v000=ParseString(v000),persistent v001 v002 v003,if isempty(v001),v003=zeros(1,...
double('u'));v003(double('"\/bfnrtu'))=[ones(1,8) 5]+1;v001={'"','"';'\','\';'/','/';'b',...
char(8);'f',char(12);'n',char(10);'r',char(13);'t',char(9)};v002=double([cell2mat(v001(:,1));
'u']);for v004=1:size(v001,1),v001{v004,1}=['\' v001{v004,1}];end,end,if~strcmp(v000([1 end]),...
'""'),v005='Unexpected end of string.';v006='StringDelim';throw_error(v005,v006),end,if ...
any(double(v000)<32),v005='Unescaped control character in string.';v006='StringControlChar';
throw_error(v005,v006),end,v000=v000(2:(end-1));v007=regexp(v000,'\\.');if any(v007),...
if~all(ismember(double(v000(v007+1)),v002)),v005='Unexpected escaped character.';v006=...
'StringEscape';throw_error(v005,v006),end,v007=regexp(v000,'\\["\\/bfnrtu]');v008=strfind(v000,...
'\u');if~isempty(v008),v009=true;try v008=bsxfun_plus(v008.',0:5);v010=...
cellstr(unique(v000(v008),'rows'));for v004=1:numel(v010),v010{v004,2}=...
unicode_to_char(hex2dec(v010{v004,1}(3:end)));end,catch,v005='Unexpected escaped character.';
v006='StringEscape';throw_error(v005,v006),end,else,v009=false;v010=cell(0,2);end,v011=[v010;
v001];v012=v003(v000(v007+1));v012=[0 v012;diff([0,v007,1+numel(v000)])-[1 v012]];v013=...
mat2cell(v000,1,v012(:));v013=reshape(v013,2,[]);if any([v013{2,:}]=='\'),v005=...
'Unexpected escaped character.';v006='StringEscape';throw_error(v005,v006),end,v014=...
true(size(v013));v014(1,:)=false;v014(cellfun('prodofsize',v013)==0)=true;for v004=1:size(v011,...
1),v015=~v014&ismember(v013,v011{v004,1});v013(v015)=v011(v004,2);v014(v015)=true;if all(v014),...
break,end,end,if any(~v014),v005='Unexpected escaped character.';v006='StringEscape';
throw_error(v005,v006),end,v000=horzcat(v013{:});if v009&&CharIsUTF8,[v000,v016]=...
UTF8_to_unicode(v000);v000=unicode_to_char(UTF16_to_unicode(v000));end,end,end
function v000=ParseNumber(v001,v002),if~v002,v003=true;else,v004{1}=...
['-?((0)|([1-9]+\d*))(\.\d+)?([eE]' '\+' '?[0-9]+)?'];v004{2}=...
['-?((0)|([1-9]+\d*))(\.\d+)?([eE]' '-' '?[0-9]+)?'];if true,[v005,v006]=regexp(v001,v004{1},...
'once');v003=~isempty(v005)&&v005==1&&v006==numel(v001);end,if~v003,[v005,v006]=regexp(v001,...
v004{2},'once');v003=~isempty(v005)&&v005==1&&v006==numel(v001);end,end,if~v003,v007=...
'Invalid number format.';v008='Number';throw_error(v007,v008),end,v000=str2double(v001);end
function v000=ParseArray(v001),v002=find(v001.braces==-v001.braces(1));if numel(v002)~=1||v002~=...
numel(v001.str)||~strcmp(v001.str([1 end]),'[]'),v003='Unexpected end of array.';v004='Array';
throw_error(v003,v004),end,if strcmp(v001.str,'[]'),v000=[];return,end,if strcmp(v001.str,...
'[[]]'),v000={[]};return,end,v005=v001.braces;v005(1)=0;v006=find(cumsum(v005)==...
0&v001.s_tokens==',');v006=[1 v006 numel(v001.str)];v006=[v006(1:(end-1))+1;v006(2:end)-1];if ...
any(diff(v006,1,1)<0),v003='Empty array element.';v004='Array';throw_error(v003,v004),end,v000=...
cell(size(v006,2),1);for v007=1:size(v006,2),v000{v007}=ParseValue(index(v001,v006(:,v007)));
end,if v001.ArrayOfArrays(1),try if~all(cellfun('isclass',v000,class(v000{1}))),...
error('trigger'),end,v008=v000;v008(cellfun('isempty',v008))={NaN};v000=horzcat(v008{:}).';
return,catch,end,end,if ismember(class(v000{v007}),{'double','logical','struct'}),v008=v000;if ...
all(cellfun('isclass',v000,'double')),v008(cellfun('isempty',v008))={NaN};if ...
numel(unique(cellfun('prodofsize',v008)))==1,v000=horzcat(v008{:}).';return,end,elseif ...
all(cellfun('isclass',v000,'logical')),if numel(unique(cellfun('prodofsize',v000)))==1,v000=...
horzcat(v000{:}).';return,end,elseif all(cellfun('isclass',v000,'struct')),try v000=...
vertcat(v000{:});catch,end,else,end,end,end
function[v000,v001]=parse_NameValue(v002,varargin),switch numel(v002),case 0,...
error('parse_NameValue:MixedOrBadSyntax',...
'Optional inputs must be entered as Name,Value pairs or as a scalar struct.'),case 1,otherwise,...
v002=v002(1);end,v000=v002;v001={};if nargin==1,return,end,try v003=numel(varargin)==...
1&&isa(varargin{1},'struct');v004=mod(numel(varargin),2)==0&&all(cellfun('isclass',...
varargin(1:2:end),'char')|cellfun('isclass',varargin(1:2:end),'string'));if~(v003||v004),...
error('trigger'),end,if nargin==2,v005=fieldnames(varargin{1});v006=struct2cell(varargin{1});
else,v005=cellstr(varargin(1:2:end));v006=varargin(2:2:end);end,if~iscellstr(v005),...
error('trigger');end,catch,error('parse_NameValue:MixedOrBadSyntax',...
'Optional inputs must be entered as Name,Value pairs or as a scalar struct.'),end,v007=...
fieldnames(v002);v008=cell(1,4);v009{1}=v007;v009{2}=lower(v009{1});v009{3}=strrep(v009{2},'_',...
'');v009{4}=strrep(v009{3},'-','');v005=strrep(v005,' ','_');v001=false(size(v007));for v010=...
1:numel(v005),v011=v005{v010};[v012,v008{1}]=parse_NameValue__find_match(v008{1},v009{1},v011);
if numel(v012)~=1,v011=lower(v011);[v012,v008{2}]=parse_NameValue__find_match(v008{2},v009{2},...
v011);end,if numel(v012)~=1,v011=strrep(v011,'_','');[v012,v008{3}]=...
parse_NameValue__find_match(v008{3},v009{3},v011);end,if numel(v012)~=1,v011=strrep(v011,'-',...
'');[v012,v008{4}]=parse_NameValue__find_match(v008{4},v009{4},v011);end,if numel(v012)~=1,...
error('parse_NameValue:NonUniqueMatch',v005{v010}),end,v000.(v007{v012})=v006{v010};v001(v012)=...
true;end,v001=v007(v001);end
function[v000,v001]=parse_NameValue__find_match(v001,v002,v003),v000=find(ismember(v002,v003));
if numel(v000)==1,return,end,if isempty(v001),v001=parse_NameValue__name2char(v002);end,v004=...
v001(:,1:min(end,numel(v003)));if size(v004,2)<numel(v003),v004=[v004 repmat(' ',size(v004,1),...
numel(v003)-size(v004,2))];end,v005=numel(v003)-sum(cumprod(double(v004==repmat(v003,size(v004,...
1),1)),2),2);v000=find(v005==0);end
function error_(v001,varargin),persistent v000,if isempty(v000),v000=func2str(@error_);end,if ...
isempty(v001),v001=struct;end,v001=parse_warning_error_redirect_options(v001);[v002,v003,v004,...
v005,v006]=parse_warning_error_redirect_inputs(varargin{:});if v006,return,end,if ...
v001.params.ShowTraceInMessage,v003=sprintf('%s\n%s',v003,v005);end,v007=struct('identifier',...
v002,'message',v003,'stack',v004);if v001.params.WipeTraceForBuiltin,v007.stack=v004('name','',...
'file','','line',[]);end,if v001.boolean.obj,v008=v003;while v008(end)==10,v008(end)='';end,if ...
any(v008==10),v008=char2cellstr(['Error: ' v008]);else,v008=['Error: ' v008];end,for v009=...
v001.obj(:).',try set(v009,'String',v008);catch,end,end,end,if v001.boolean.fid,v010=...
datestr(now,31);for v011=v001.fid(:).',try fprintf(v011,'[%s] Error: %s\n%s',v010,v003,v005);
catch,end,end,end,if v001.boolean.fcn,if ismember(v000,{v004.name}),error('prevent recursion'),...
end,for v012=v001.fcn(:).',if isfield(v012,'data'),try feval(v012.h,'error',v007,v012.data);
catch,end,else,try feval(v012.h,'error',v007);catch,end,end,end,end,rethrow(v007),end
function[v000,v001]=filename_is_valid(v001),v000=true;persistent v002,if isempty(v002),v002=...
{'CON','PRN','AUX','NUL','COM1','COM2','COM3','COM4','COM5','COM6','COM7','COM8','COM9','LPT1',...
'LPT2','LPT3','LPT4','LPT5','LPT6','LPT7','LPT8','LPT9'};end,if isa(v001,...
'string')&&numel(v001)==1,v001=char(v001);end,if~isa(v001,'char')||numel(v001)==0,v000=false;
return,else,[v003,v004,v005]=fileparts(v001);v004=[v004,v005];if any(ismember([char(0:31) ...
'<>:"/\|?*'],v004))||any(ismember(v002,upper(v004)))||any(v004(end)=='. '),v000=false;return,...
end,end,end
function v000=convert_from_codepage(v000,v001),persistent v002 v003,if isempty(v002),v004=[338 ...
140;339 156;352 138;353 154;376 159;381 142;382 158;402 131;710 136;732 152;8211 150;8212 151;
8216 145;8217 146;8218 130;8220 147;8221 148;8222 132;8224 134;8225 135;8226 149;8230 133;8240 ...
137;8249 139;8250 155;8364 128;8482 153];v002=v004(:,2);v003=v004(:,1);end,if nargin>1&&v001,...
v005=v003;v006=v002;else,v005=v002;v006=v003;end,v000=uint32(v000);for v007=1:numel(v005),v000=...
PatternReplace(v000,v005(v007),v006(v007));end,end
function v000=parse_NameValue__name2char(v000),v001=cellfun('prodofsize',v000);v002=max(v001);
for v003=find(v001<v002).',v000{v003}((end+1):v002)=' ';end,v000=vertcat(v000{:});end
function[v002,v003]=parse_print_to___get_default,persistent v000 v001,if isempty(v000),[v000,...
v001]=parse_print_to___get_default_helper;end,v002=v000;v003=v001;end
function varargout=findND(v000,varargin),if~(isnumeric(v000)||islogical(v000))||numel(v000)==0,...
error('HJW:findND:FirstInput',...
'Expected first input (X) to be a non-empty numeric or logical array.'),end,switch nargin,case ...
1,v001='first';v002=inf;case 2,v001='first';v002=varargin{1};
if~(isnumeric(v002)||islogical(v002))||numel(v002)~=1||any(v002<0),...
error('HJW:findND:SecondInput',...
'Expected second input (K) to be a positive numeric or logical scalar.'),end,case 3,v002=...
varargin{1};if~(isnumeric(v002)||islogical(v002))||numel(v002)~=1||any(v002<0),...
error('HJW:findND:SecondInput',...
'Expected second input (K) to be a positive numeric or logical scalar.'),end,v001=varargin{2};
if isa(v001,'string')&&numel(v001)==1,v001=char(v001);end,if~isa(v001,'char')||~(strcmpi(v001,...
'first')||strcmpi(v001,'last')),error('HJW:findND:ThirdInput',...
'Third input must be either ''first'' or ''last''.'),end,v001=lower(v001);otherwise,...
error('HJW:findND:InputNumber','Incorrect number of inputs.'),end,if ...
nargout>1&&nargout<ndims(v000),error('HJW:findND:Output',...
'Incorrect number of output arguments.'),end,persistent v003,if isempty(v003),v003=...
ifversion('<',7,'Octave','<',3);end,varargout=cell(max(1,nargout),1);if v003,if ...
nargout>ndims(v000),[v004,v005,v006]=find(v000(:));if length(v004)>v002,if strcmp(v001,'first'),...
v004=v004(1:v002);v006=v006(1:v002);else,v004=v004((end-v002+1):end);v006=...
v006((end-v002+1):end);end,end,[varargout{1:(end-1)}]=ind2sub(size(v000),v004);varargout{end}=...
v006;else,v004=find(v000);if numel(v004)>v002,if strcmp(v001,'first'),v004=v004(1:v002);else,...
v004=v004((end-v002+1):end);end,end,[varargout{:}]=ind2sub(size(v000),v004);end,else,if ...
nargout>ndims(v000),[v004,v005,v006]=find(v000(:),v002,v001);[varargout{1:(end-1)}]=...
ind2sub(size(v000),v004);varargout{end}=v006;else,v004=find(v000,v002,v001);[varargout{:}]=...
ind2sub(size(v000),v004);end,end,end
function v000=StrToNotation(v001,v002),if isa(v001,'string'),v001=cellstr(v001);end,if ...
iscellstr(v001),v001=sprintf('%s\n',v001{:});end,if~isa(v001,'char')||numel(v001)~=length(v001),...
throw_error('The input should be a char vector or a string/cellstr.','Input'),end,v001=...
reshape(v001,1,[]);persistent v003 v004 v005,if isempty(v003),v004=[9 10 13 32];v003={['[' ...
char(v004) ']*([\[{\]}:,])[' char(v004) ']*'],'$1','tokenize'};if ifversion('>=',7,'Octave','>',...
0),v003(end)=[];end,v005=3==numel(regexprep(['123' char([0 10])],v003{:}));end,v006=...
FindLiteralTextPositions(v001);v007=v001;v007(v006)='_';if~v005,v007=regexprep(v007,v003{:});
else,v008=v007;v008(:)='n';v008(ismember(double(v007),v004))='w';v008(ismember(double(v007),...
double('[{}]:,')))='t';v009=zeros(1,1+numel(v008));[v010,v011]=regexp(v008,'w+t');
if~isempty(v010),v009(v010)=1;v009(v011)=-1;end,[v010,v011]=regexp(v008,'tw+');if~isempty(v010),...
v009(v010+1)=1;v009(v011+1)=-1;end,v009=logical(cumsum(v009));v009(end)=[];v007(v009)='';end,...
while numel(v007)>0&&any(v007(end)==v004),v007(end)='';end,while numel(v007)>0&&any(v007(1)==...
v004),v007(1)='';end,v012=v007;v012(v007=='_')=v001(v006);v001=v012;v007(~ismember(double(v007),...
double('[{}]:,')))='_';[v013,v014]=PairBraces(v007);v000.str=v001;v000.s_tokens=v007;
v000.braces=v013;v000.ArrayOfArrays=v014;v000.opts=v002;v000.depth=0;end
function v000=char2cellstr(v001,v002),v003=isa(v001,'char');v001=int32(v001);if nargin<2,if ...
any(v001==13),v001=PatternReplace(v001,int32([13 10]),int32(-10));v001(v001==13)=-10;end,...
v001(v001==10)=-10;else,for v004=1:numel(v002),v001=PatternReplace(v001,int32(v002{v004}),...
int32(-10));end,end,v005=[0 find(v001==-10) numel(v001)+1];v000=cell(numel(v005)-1,1);for v004=...
1:numel(v000),v006=(v005(v004)+1);v007=(v005(v004+1)-1);v000{v004}=v001(v006:v007);end,if v003,...
for v004=1:numel(v000),v000{v004}=char(v000{v004});end,else,for v004=1:numel(v000),v000{v004}=...
uint32(v000{v004});end,end,end
function[v000,v001]=get_trace(v002,v001),if nargin==0,v002=1;end,if nargin<2,v001=dbstack;end,...
v001(1:v002)=[];if~isfield(v001,'file'),for v003=1:numel(v001),v004=v001(v003).name;if ...
strcmp(v004(end),')'),v005=strfind(v004,'(');v006=v004((v005(end)+1):(end-1));v007=...
v004(1:(v005(end)-2));else,v007=v004;[v008,v006]=fileparts(v004);end,[v008,v001(v003).file]=...
fileparts(v007);v001(v003).name=v006;end,end,persistent v009,if isempty(v009),v009=...
ifversion('<',0,'Octave','>',0);end,if v009,for v003=1:numel(v001),[v008,v001(v003).file]=...
fileparts(v001(v003).file);end,end,v010=v001;v011='>';v000=cell(1,numel(v010)-1);for v003=...
1:numel(v010),[v012,v010(v003).file,v013]=fileparts(v010(v003).file);if v003==numel(v010),...
v010(v003).file='';end,if strcmp(v010(v003).file,v010(v003).name),v010(v003).file='';end,...
if~isempty(v010(v003).file),v010(v003).file=[v010(v003).file '>'];end,v000{v003}=...
sprintf('%c In %s%s (line %d)\n',v011,v010(v003).file,v010(v003).name,v010(v003).line);v011=' ';
end,v000=horzcat(v000{:});end
function[v001,v004]=parse_print_to___get_default_helper,v000=struct('ShowTraceInMessage',false,...
'WipeTraceForBuiltin',false);v001=struct('params',v000,'fid',[],'obj',[],'fcn',struct('h',{},...
'data',{}),'boolean',struct('con',[],'fid',false,'obj',false,'fcn',false,'IsValidated',false));
v002=fieldnames(v000);for v003=1:numel(v002),v002{v003}=['option_' v002{v003}];end,v004=...
[{'params'};v002;{'con';'fid';'obj';'fcn'}];for v003=1:numel(v004),v004{v003}=['print_to_' ...
v004{v003}];end,v004=sort(v004);end
function[v000,v001]=test_if_scalar_logical(v001),persistent v002,if isempty(v002),v002={true,...
false;1,0;'on','off';'enable','disable';'enabled','disabled'};end,if isa(v001,...
'matlab.lang.OnOffSwitchState'),v000=true;v001=logical(v001);return,end,if isa(v001,'string'),...
if numel(v001)~=1,v000=false;return,else,v001=char(v001);end,end,if isa(v001,'char'),v001=...
lower(v001);end,for v003=1:size(v002,1),for v004=1:2,if isequal(v001,v002{v003,v004}),v000=true;
v001=v002{1,v004};return,end,end,end,v000=false;end
function v000=ifversion(v001,v002,v003,v004,v005),persistent v006 v007 v008,if isempty(v006),...
v008=exist('OCTAVE_VERSION','builtin');v006=[100,1] * sscanf(version,'%d.%d',2);v007={'R13' 605;
'R13SP1' 605;'R13SP2' 605;'R14' 700;'R14SP1' 700;'R14SP2' 700;'R14SP3' 701;'R2006a' 702;
'R2006b' 703;'R2007a' 704;'R2007b' 705;'R2008a' 706;'R2008b' 707;'R2009a' 708;'R2009b' 709;
'R2010a' 710;'R2010b' 711;'R2011a' 712;'R2011b' 713;'R2012a' 714;'R2012b' 800;'R2013a' 801;
'R2013b' 802;'R2014a' 803;'R2014b' 804;'R2015a' 805;'R2015b' 806;'R2016a' 900;'R2016b' 901;
'R2017a' 902;'R2017b' 903;'R2018a' 904;'R2018b' 905;'R2019a' 906;'R2019b' 907;'R2020a' 908;
'R2020b' 909;'R2021a' 910;'R2021b' 911;'R2022a' 912;'R2022b' 913;'R2023a' 914};end,if v008,if ...
nargin==2,warning('HJW:ifversion:NoOctaveTest',['No version test for Octave was provided.',...
char(10),'This function might return an unexpected outcome.']),if isnumeric(v002),v009=...
0.1*v002+0.9*fix(v002);v009=round(100*v009);else,v010=ismember(v007(:,1),v002);if sum(v010)~=1,...
warning('HJW:ifversion:NotInDict','The requested version is not in the hard-coded list.'),v000=...
NaN;return,else,v009=v007{v010,2};end,end,elseif nargin==4,[v001,v009]=deal(v003,v004);v009=...
0.1*v009+0.9*fix(v009);v009=round(100*v009);else,[v001,v009]=deal(v004,v005);v009=...
0.1*v009+0.9*fix(v009);v009=round(100*v009);end,else,if isnumeric(v002),v009=...
0.1*v002+0.9*fix(v002);v009=round(100*v009);else,v010=ismember(v007(:,1),v002);if sum(v010)~=1,...
warning('HJW:ifversion:NotInDict','The requested version is not in the hard-coded list.'),v000=...
NaN;return,else,v009=v007{v010,2};end,end,end,switch v001,case'==',v000=v006==v009;case'<',v000=...
v006 < v009;case'<=',v000=v006 <=v009;case'>',v000=v006 > v009;case'>=',v000=v006 >=v009;end,end
function v002=GetPseudoAddonpath,if ispc,[v000,v001]=system('echo %APPDATA%');v001(v001<14)='';
v002=fullfile(v001,'MathWorks','MATLAB Add-Ons');else,[v000,v003]=system('echo $HOME');
v003(v003<14)='';v002=fullfile(v003,'Documents','MATLAB','Add-Ons');end,end
function v000=hasFeature(v001),persistent v002,if isempty(v002),v002=struct('ImplicitExpansion',...
ifversion('>=','R2016b','Octave','>',0),'bsxfun',ifversion('>=','R2007a','Octave','>',0),...
'IntegerArithmetic',ifversion('>=','R2010b','Octave','>',0),'String',ifversion('>=','R2016b',...
'Octave','<',0),'HTTPS_support',ifversion('>',0,'Octave','<',0),'json',ifversion('>=','R2016b',...
'Octave','>=',7),'strtrim',ifversion('>=',7,'Octave','>=',0),'accumarray',ifversion('>=',7,...
'Octave','>=',0));v002.CharIsUTF8=CharIsUTF8;end,v000=v002.(v001);end
function[v000,v001,v002]=GetWritableFolder_parse_inputs(varargin),v000=false;v002=...
struct('identifier','','message','');persistent v003,if isempty(v003),v003.ForceStatus=false;
v003.ErrorOnNotFound=false;v003.root_folder_list={GetPseudoAddonpath;fullfile(tempdir,'MATLAB');
''};end,if nargin==2,v001=v003;v000=true;return,end,[v001,v004]=parse_NameValue(v003,...
varargin{:});for v005=1:numel(v004),v006=v004{v005};v007=v001.(v006);v002.identifier=...
['HJW:GetWritableFolder:incorrect_input_opt_' lower(v006)];switch v006,case'ForceStatus',try ...
if~isa(v003.root_folder_list{v007},'char'),...
error('the indexing must have failed, trigger error'),end,catch,v002.message=...
sprintf('Invalid input: expected a scalar integer between 1 and %d.',...
numel(v003.root_folder_list));return,end,case'ErrorOnNotFound',[v008,v001.ErrorOnNotFound]=...
test_if_scalar_logical(v007);if~v008,v002.message=...
'ErrorOnNotFound should be either true or false.';return,end,otherwise,v002.message=...
sprintf('Name,Value pair not recognized: %s.',v006);v002.identifier=...
'HJW:GetWritableFolder:incorrect_input_NameValue';return,end,end,v000=true;v002=[];end
function[v000,v001]=GetWritableFolder(varargin),[v002,v003,v004]=...
GetWritableFolder_parse_inputs(varargin{:});if~v002,rethrow(v004),else,[v005,v006,v007]=...
deal(v003.ForceStatus,v003.ErrorOnNotFound,v003.root_folder_list);end,v007{end}=pwd;if v005,...
v001=v005;v000=fullfile(v007{v001},'PersistentFolder');try if~exist(v000,'dir'),mkdir(v000);end,...
catch,end,return,end,v001=1;v000=v007{v001};try if~exist(v000,'dir'),mkdir(v000);end,catch,end,...
if~TestFolderWritePermission(v000),v001=2;v000=v007{v001};try if~exist(v000,'dir'),mkdir(v000);
end,catch,end,if~TestFolderWritePermission(v000),v001=3;v000=v007{v001};end,end,v000=...
fullfile(v000,'PersistentFolder');try if~exist(v000,'dir'),mkdir(v000);end,catch,end,...
if~TestFolderWritePermission(v000),if v006,error('HJW:GetWritableFolder:NoWritableFolder',...
'This function was unable to find a folder with write permissions.'),else,v001=0;v000='';end,...
end,end
function v000=parse_print_to___named_fields_to_struct(v001),persistent v002 v003 v004,if ...
isempty(v003),[v002,v003]=parse_print_to___get_default;v005='print_to_option_';for v006=...
numel(v003):-1:1,if~strcmp(v005,v003{v006}(1:min(end,numel(v005)))),v003(v006)=[];end,end,v004=...
strrep(v003,v005,'');end,v000=v002;if isfield(v001,'print_to_params'),v000.params=...
v001.print_to_params;else,for v006=1:numel(v003),v007=v003{v006};if isfield(v001,v003{v006}),...
v008=v004{v006};v000.params.(v008)=v001.(v007);end,end,end,if isfield(v001,'print_to_fid'),...
v000.fid=v001.print_to_fid;end,if isfield(v001,'print_to_obj'),v000.obj=v001.print_to_obj;end,...
if isfield(v001,'print_to_fcn'),v000.fcn=v001.print_to_fcn;end,if isfield(v001,'print_to_con'),...
v000.boolean.con=v001.print_to_con;end,v000.boolean.IsValidated=false;end
function[v000,v001,v002]=parse_print_to___validate_struct(v002),v003=nargout>=3;v001=...
struct('identifier','','message','');v000=true;if nargout>=3,v003=true;end,[v004,v005]=...
test_if_scalar_logical(v002.boolean.IsValidated);if v004&&v005,return,end,[v004,...
v002.boolean.con]=test_if_scalar_logical(v002.boolean.con);if~v004&&~isempty(v002.boolean.con),...
v001.message=['Invalid print_to_con parameter:',char(10),...
'should be a scalar logical or empty double.'];v001.identifier='HJW:print_to:ValidationFailed';
v000=false;if~v003,return,end,end,[v006,v002.fid]=validate_fid(v002.fid);if v006,v001.message=...
['Invalid print_to_fid parameter:',char(10),'should be a valid file identifier or 1.'];
v001.identifier='HJW:print_to:ValidationFailed';v000=false;if~v003,return,end,end,...
v002.boolean.fid=~isempty(v002.fid);[v006,v002.obj]=validate_obj(v002.obj);if v006,v001.message=...
['Invalid print_to_obj parameter:',char(10),...
'should be a handle to an object with a writeable String property.'];v001.identifier=...
'HJW:print_to:ValidationFailed';v000=false;if~v003,return,end,end,v002.boolean.obj=...
~isempty(v002.obj);[v006,v002.fcn]=validate_fcn(v002.fcn);if v006,v001.message=...
['Invalid print_to_fcn parameter:',char(10),...
'should be a struct with the h field containing a function handle,',char(10),...
'anonymous function or inline function.'];v001.identifier='HJW:print_to:ValidationFailed';v000=...
false;if~v003,return,end,end,v002.boolean.fcn=~isempty(v002.fcn);[v006,v002.params]=...
validate_params(v002.params);if v006,v001.message=['Invalid print_to____params parameter:',...
char(10),'should be a scalar struct uniquely matching parameter names.'];v001.identifier=...
'HJW:print_to:ValidationFailed';v000=false;if~v003,return,end,end,if isempty(v002.boolean.con),...
v002.boolean.con=~any([v002.boolean.fid v002.boolean.obj v002.boolean.fcn]);end,if~v000,...
v002.boolean.con=true;end,v002.boolean.IsValidated=true;end
function[v000,v001]=validate_fid(v001),v000=false;for v002=numel(v001):-1:1,try v003=...
ftell(v001(v002));catch,v003=-1;end,if v001(v002)~=1&&v003==-1,v000=true;v001(v002)=[];end,end,...
end
function[v000,v001]=validate_obj(v001),v000=false;for v002=numel(v001):-1:1,try v003=...
get(v001(v002),'String');set(v001(v002),'String','');set(v001(v002),'String',v003);catch,v000=...
true;v001(v002)=[];end,end,end
function[v000,v001]=validate_fcn(v001),v000=false;for v002=numel(v001):-1:1,...
if~ismember(class(v001(v002).h),{'function_handle','inline'})||numel(v001(v002).h)~=1,v000=true;
v001(v002)=[];end,end,end
function[v000,v001]=validate_params(v001),v000=false;persistent v002,if isempty(v002),v002=...
parse_print_to___get_default;v002=v002.params;end,if isempty(v001),v001=struct;end,if~isa(v001,...
'struct'),v000=true;v001=v002;return,end,while true,try v003=[];[v001,v004]=...
parse_NameValue(v002,v001);break,catch v003;if isempty(v003),v003=lasterror;end,v000=true;v001=...
rmfield(v001,v003.message);end,end,for v005=1:numel(v004),v006=v004{v005};switch v006,...
case'ShowTraceInMessage',[v007,v001.(v006)]=test_if_scalar_logical(v001.(v006));if~v007,v000=...
true;v001.(v006)=v002.(v006);end,case'WipeTraceForBuiltin',[v007,v001.(v006)]=...
test_if_scalar_logical(v001.(v006));if~v007,v000=true;v001.(v006)=v002.(v006);end,end,end,end
function[v000,v001,v002,v003,v004]=parse_varargin_robust(v005,varargin),v000=false;v003=false;
v002=struct('identifier','','message','');v004=cell(0);try v006=[];[v001,v004]=...
parse_NameValue(v005,varargin{:});catch v006;if isempty(v006),v006=lasterror;end,v002=v006;v003=...
true;end,if v003,if isa(varargin{1},'struct'),v001=varargin{1};else,try v001=...
struct(varargin{:});catch,v001=struct;end,end,if isfield(v001,'print_to'),v007=v001.print_to;
else,v007=parse_print_to___named_fields_to_struct(v001);end,else,if ismember('print_to',v004),...
v007=v001.print_to;else,v007=parse_print_to___named_fields_to_struct(v001);end,end,[v008,v009,...
v001.print_to]=parse_print_to___validate_struct(v007);if~v008,v002=v009;v003=true;end,end
function v000=UTF16_to_unicode(v001),persistent v002,if isempty(v002),v002=...
exist('OCTAVE_VERSION','builtin') ~=0;end,v001=uint32(v001);v003=v001>55295&v001<57344;
if~any(v003),v000=v001;return,end,v004=find(v001>=55296&v001<=56319);v005=find(v001>=...
56320&v001<=57343);try v006=v005-v004;if any(v006~=1)||isempty(v006),error('trigger error'),end,...
catch,error('input is not valid UTF-16 encoded'),end,v007='110110110111';v008=[1:6 17:22];v003=...
v001([v004.' v005.']);v003=unique(v003,'rows');v009=mat2cell(v003,ones(size(v003,1),1),2);v000=...
v001;for v010=1:numel(v009),v011=dec2bin(double(v009{v010}))';if~strcmp(v007,v011(v008)),...
error('input is not valid UTF-16 encoded'),end,v011(v008)='';if~v002,v012=uint32(bin2dec(v011));
else,v012=uint32(bin2dec(v011.'));end,v012=v012+65536;v000=PatternReplace(v000,v009{v010},v012);
end,end
function[v000,v001,v002]=UTF8_to_unicode(v003,v004),if nargin<2,v004=[];end,v005=nargout==1;
v003=uint32(reshape(v003,1,[]));[v002,v006,v007]=UTF8_to_unicode_internal(v003,v005);if ...
strcmp(v006,'success'),v001=true;v000=v002;elseif strcmp(v006,'error'),v001=false;if v005,...
error_(v004,v007),end,v000=v003;end,end
function v000=unicode_to_UTF8(v001),if numel(v001)>1,...
error('this should only be used for single characters'),end,if v001<128,v000=v001;return,end,...
persistent v002,if isempty(v002),v002=struct;v002.limits.lower=hex2dec({'0000','0080','0800',...
'10000'});v002.limits.upper=hex2dec({'007F','07FF','FFFF','10FFFF'});v002.scheme{2}=...
'110xxxxx10xxxxxx';v002.scheme{2}=reshape(v002.scheme{2}.',8,2);v002.scheme{3}=...
'1110xxxx10xxxxxx10xxxxxx';v002.scheme{3}=reshape(v002.scheme{3}.',8,3);v002.scheme{4}=...
'11110xxx10xxxxxx10xxxxxx10xxxxxx';v002.scheme{4}=reshape(v002.scheme{4}.',8,4);for v003=2:4,...
v002.scheme_pos{v003}=find(v002.scheme{v003}=='x');v002.bits(v003)=numel(v002.scheme_pos{v003});
end,end,v004=find(v002.limits.lower<=v001&v001<=v002.limits.upper);v000=v002.scheme{v004};v005=...
v002.scheme_pos{v004};v003=dec2bin(double(v001),v002.bits(v004));v000(v005)=v003;v000=...
bin2dec(v000.').';end
function[v000,v001,v002]=UTF8_to_unicode_internal(v000,v003),v001='success';v002=...
struct('identifier','HJW:UTF8_to_unicode:notUTF8','message','Input is not UTF-8.');persistent ...
v004,if isempty(v004),v004=ifversion('<',0,'Octave','>',0);end,if any(v000>255),v001='error';if ...
v003,return,end,elseif all(v000<128),return,end,for v005=4:-1:2,v006=bin2dec([repmat('1',1,...
v005) repmat('0',1,8-v005)]);v007=v000>=v006&v000<256;if any(v007),v007=find(v007);v007=...
v007(:).';if numel(v000)<(max(v007)+v005-1),v001='error';if v003,return,end,...
v007((v007+v005-1)>numel(v000))=[];end,if~isempty(v007),v008=bsxfun_plus(v007,(0:(v005-1)).');
v008=v008.';v007=v000(v008);end,else,v007=[];end,v009=[repmat('1',1,v005-1) repmat('10',1,...
v005)];v010=unique([1:(v005+1) 1:8:(8*v005) 2:8:(8*v005)]);if numel(v007)>0,v007=unique(v007,...
'rows');v011=mat2cell(v007,ones(size(v007,1),1),v005);for v012=1:numel(v011),v013=...
dec2bin(double(v011{v012}))';if~strcmp(v009,v013(v010)),v001='error';if v003,return,end,...
continue,end,v013(v010)='';if~v004,v014=uint32(bin2dec(v013));else,v014=uint32(bin2dec(v013.'));
end,v000=PatternReplace(v000,v011{v012},v014);end,end,end,end
function[v000,v001,v002,v003,v004]=parse_warning_error_redirect_inputs(varargin),v004=false;if ...
nargin==1,if isa(varargin{1},'struct')||isa(varargin{1},'MException'),v005=varargin{1};if ...
numel(v005)~=1,v004=true;[v000,v001,v002,v003]=deal('');return,end,try v002=v005.stack;v003=...
get_trace(0,v002);catch,[v003,v002]=get_trace(3);end,v000=v005.identifier;v001=v005.message;
v006='Error using ==> ';if strcmp(v001(1:min(end,numel(v006))),v006),v007=...
min(find(ismember(double(v001),[10 13])));if any(double(v001(v007+1))==[10 13]),v007=v007-1;end,...
v001(1:v007)='';end,v006=...
'Error using <a href="matlab:matlab.internal.language.introspective.errorDocCallbac';if ...
isa(v005,'struct')&&strcmp(v006,v001(1:min(end,numel(v006)))),v001(1:min(find(v001==10)))='';
end,else,[v003,v002]=get_trace(3);[v000,v001]=deal('',varargin{1});end,else,[v003,v002]=...
get_trace(3);if~isempty(strfind(varargin{1},'%')),v000='';v008=varargin(2:end);v001=...
sprintf(varargin{1},v008{:});else,v000=varargin{1};v001=varargin{2};if nargin>2,v008=...
varargin(3:end);v001=sprintf(v001,v008{:});end,end,end,end
function v000=parse_warning_error_redirect_options(v000),if isfield(v000,...
'boolean')&&isfield(v000.boolean,'IsValidated')&&v000.boolean.IsValidated,return,end,try v001=...
parse_NameValue(parse_print_to___get_default,v000);v001.boolean.IsValidated=false;catch,v001=...
parse_print_to___named_fields_to_struct(v000);end,[v002,v002,v000]=...
parse_print_to___validate_struct(v001);end
function v000=PatternReplace(v001,v002,v003),v001=reshape(v001,1,[]);v000=v001;if numel(v002)==...
0||numel(v002)>numel(v001),return,end,v004=true(size(v001));v004((end-numel(v002)+2):end)=false;
for v005=1:numel(v002),v006=v001==v002(v005);v006=circshift(v006,[0 1-v005]);v006(1:(v005-1))=...
v004(1:(v005-1));v004=v004&v006;if~any(v004),return,end,end,if numel(v003)==0,v000(v004)=[];
return,end,if numel(v002)>1,v007=bsxfun_plus(find(v004),reshape(1:(numel(v002)-1),[],1));else,...
v007=find(v004);end,v007=reshape(v007,1,[]);v008=repmat(' ',1,numel(v001));v008(v007)='_';
v008(v004)='*';v009=v008==' ';v008=regexprep(v008,'\*_*',['*' repmat('_',1,numel(v003)-1)]);
v000(v008==' ')=v001(v009);v010=strfind(v008,'*');v007=bsxfun_plus(v010,...
reshape(0:(numel(v003)-1),[],1));v007=reshape(v007,1,[]);v000(v007)=repmat(v003,1,numel(v010));
v000((numel(v008)+1):end)=[];end
function[v000,v001]=JSON(v002,varargin),v003=struct;v003.EnforceValidNumber=true;
v003.ThrowErrorForInvalid=nargout<2;v003.MaxRecursionDepth=101-numel(dbstack);v003=...
parse_NameValue(v003,varargin{:});v004=struct;[v004.msg,v004.ID]=lastwarn;v004.w=warning('off',...
'REGEXP:multibyteCharacters');try v001=[];v005=StrToNotation(v002,v003);v000=ParseValue(v005);
catch v001;if isempty(v001),v001=lasterror;end,end,warning(v004.w);lastwarn(v004.msg,v004.ID);
if~isempty(v001),if v003.ThrowErrorForInvalid,rethrow(v001),else,v000=[];end,end,end
function v000=readfile(v001,varargin),if nargin<1,error('HJW:readfile:nargin',...
'Incorrect number of input arguments.'),end,if~(nargout==0||nargout==1),...
error('HJW:readfile:nargout','Incorrect number of output arguments.'),end,[v002,v003,v004]=...
readfile_parse_inputs(v001,varargin{:});if~v002,error_(v003.print_to,v004),else,[v001,v005,v006,...
v007,v008,v009,v010,v011,v012,v013,v014]=deal(v003.filename,v003.print_to,v003.legacy,...
v003.UseURLread,v003.err_on_ANSI,v003.EmptyLineRule,v003.Whitespace,v003.LineEnding,...
v003.FailMultiword_UTF16,v003.WhitespaceRule,v003.weboptions);end,if v003.OfflineFile,v000=...
readfile_from_file(v001,v011,v005,v008);else,if~v006.allows_https&&strcmpi(v001(1:min(end,8)),...
'https://'),warning_(v005,'HJW:readfile:httpsNotSupported',...
['This implementation of urlread probably doesn''t allow https requests.',char(10),...
'The next lines of code will probably result in an error.']),end,v015=readfile_from_URL(v001,...
v007,v005,v011,v008,v014);if isa(v015,'cell'),v000=v015;else,v016=true;v015=...
convert_from_codepage(v015,v016);try v004=[];[v017,v018,v019]=UTF8_to_unicode(v015);catch v004;
if isempty(v004),v004=lasterror;end,if strcmp(v004.identifier,'HJW:UTF8_to_unicode:notUTF8'),...
v018=false;else,error_(v005,v004),end,end,if v018,v015=unicode_to_char(v019);end,if isa(v011,...
'double')&&isempty(v011),v000=char2cellstr(v015);else,v000=char2cellstr(v015,v011);end,end,end,...
if~strcmp(v009,'read')||~strcmp(v013,'preserve'),v020=cellfun('isempty',v000);for v021=...
find(~v020).',v022=ismember(v000{v021},v010);v020(v021)=all(v022);if~strcmp(v013,'preserve'),if ...
v020(v021),v000{v021}='';continue,end,if~v022(1)&&~v022(end),continue,end,switch v013,...
case'trim',v023=find(~v022);v023=v023([1 end]);case'trimleading',v023=[findND(~v022,1) ...
numel(v022)];case'trimtrailing',v023=[1 findND(~v022,1,'last')];end,v000{v021}=...
v000{v021}(v023(1):v023(2));end,end,end,if~strcmp(v009,'read'),switch v009,case'skip',...
v000(v020)=[];case'error',if any(v020),error_(v005,'HJW:readfile:EmptyLinesRuleError',...
'Unexpected empty line detected on row %d',findND(v020,1)),end,case'skipleading',if v020(1),...
v024=1:(findND(~v020,1,'first')-1);v000(v024)=[];end,case'skiptrailing',if v020(end),v024=...
(1+findND(~v020,1,'last')):numel(v020);v000(v024)=[];end,end,end,persistent v025,if ...
isempty(v025),v025=ifversion('<',0,'Octave','>',0);end,if v012,for v021=1:numel(v000),if v025,...
if any(v000{v021}>=240),v000{v021}=replace_multiword_UTF16_by_26(v000{v021});end,else,if ...
any(v000{v021}>=55296&v000{v021}<=56319),v000{v021}=replace_multiword_UTF16_by_26(v000{v021});
end,end,end,end,end
function varargout=regexp_outkeys(v000,v001,varargin),if nargin<2,...
error('HJW:regexp_outkeys:SyntaxError','No supported syntax used: at least 3 inputs expected.'),...
end,if~(ischar(v000)&&ischar(v001)),error('HJW:regexp_outkeys:InputError',...
'All inputs must be char vectors.'),end,if nargout>nargin,error('HJW:regexp_outkeys:ArgCount',...
'Incorrect number of output arguments. Check syntax.'),end,persistent v002 v003,if ...
isempty(v002),v002.start=true;v002.end=true;v002.match=ifversion('<','R14','Octave','<',4);
v002.tokens=v002.match;v002.split=ifversion('<','R2007b','Octave','<',4);v004=fieldnames(v002);
v003=['Extra regexp output type not implemented,',char(10),'only the following',...
' types are implemented:',char(10),sprintf('%s, ',v004{:})];v003((end-1):end)='';v002.any=...
v002.match||v002.split||v002.tokens;end,if v002.any||nargin==2||any(ismember(lower(varargin),...
{'start','end'})),[v005,v006,v007]=regexp(v000,v001);end,if nargin==2,varargout={v005,v006,...
v007};return,end,varargout=cell(size(varargin));for v008=1:(nargin-2),if~ischar(varargin{v008}),...
error('HJW:regexp_outkeys:InputError','All inputs must be char vectors.'),end,switch ...
lower(varargin{v008}),case'match',if v002.match,v009=cell(1,numel(v005));for v010=1:numel(v005),...
v009{v010}=v000(v005(v010):v006(v010));end,else,[v009,v005,v006]=regexp(v000,v001,'match');end,...
varargout{v008}=v009;case'split',if v002.split,v011=cell(1,numel(v005)+1);v012=[v005 ...
numel(v000)+1];v013=[0 v006];for v010=1:numel(v012),v011{v010}=...
v000((v013(v010)+1):(v012(v010)-1));end,else,[v011,v005,v006]=regexp(v000,v001,'split');end,...
varargout{v008}=v011;case'tokens',if v002.tokens,v014=cell(numel(v007),0);for v010=...
1:numel(v007),if numel(v007{v010})~=2,v014{v010}=cell(1,0);else,v014{v010}=...
{v000(v007{v010}(1):v007{v010}(2))};end,end,else,[v014,v005,v006]=regexp(v000,v001,'tokens');
end,varargout{v008}=v014;case'start',varargout{v008}=v005;case'end',varargout{v008}=v006;
otherwise,error('HJW:regexp_outkeys:NotImplemented',v003),end,end,if nargout>v008,...
varargout(v008+[1 2])={v005,v006};end,end
function v000=readfile_from_file(v001,v002,v003,v004),persistent v005,if isempty(v005),v005=...
ifversion('<',0,'Octave','>',0);end,persistent v006,if isempty(v006),if v005,v007='Octave';else,...
v007='Matlab';end,v006=sprintf(['%s could not read the file %%s.\n',...
'The file doesn''t exist or is not readable.\n',...
'(Note that for online files, only http and https is supported.)'],v007);end,v008=...
struct('identifier','HJW:readfile:ReadFail','message',sprintf(v006,v001));v009=fopen(v001,'rb');
if v009<0,error_(v003,v008),end,v010=fread(v009,'uint8=>uint8');fclose(v009);v010=v010.';try ...
v011=[];v012=true;v013=UTF8_to_unicode(v010);catch v011;if isempty(v011),v011=lasterror;end,if ...
strcmp(v011.identifier,'HJW:UTF8_to_unicode:notUTF8'),v012=false;if v004,error_(v003,...
'HJW:readfile:notUTF8','The provided file "%s" is not a correctly encoded UTF-8 file.',v001),...
end,else,error_(v003,v011),end,end,if v005,if v012,v000=v013;else,try v000=fileread(v001);catch,...
error_(v003,v008),end,v000=convert_from_codepage(v000);end,else,if ispc,if v012,v000=v013;else,...
if ifversion('<',7),try v000=fileread(v001);catch,error_(v003,v008),end,v000=...
convert_from_codepage(v000);else,try v000=fileread(v001);catch,error_(v003,v008),end,end,end,...
else,if v012,v000=v013;else,v000=convert_from_codepage(v010);end,end,end,if numel(v000)>=...
1&&double(v000(1))==65279,v000(1)=[];end,v000=unicode_to_char(v000);if isa(v002,...
'double')&&isempty(v002),v000=char2cellstr(v000);else,v000=char2cellstr(v000,v002);end,end
function v000=replace_multiword_UTF16_by_26(v001),persistent v002,if isempty(v002),v002=...
exist('OCTAVE_VERSION','builtin') ~=0;end,if v002,v003=UTF8_to_unicode(v001);else,v003=...
UTF16_to_unicode(v001);end,v003(v003>=65536)=26;if v002,v000=char(unicode_to_UTF8(v003));else,...
v000=char(unicode_to_UTF16(v003));end,end
function v000=readfile_from_URL(v001,v002,v003,v004,v005,v006),try v007=false;v008=...
tmpname('readfile_from_URL_tmp_','.txt');try if v002,v008=urlwrite(v001,v008);else,v008=...
websave(v008,v001,v006);end,v000=readfile_from_file(v008,v004,v003,v005);catch,v007=true;end,...
try if exist(v008,'file'),delete(v008);end,catch,end,if v007,error('revert to urlread'),end,...
catch,try v009=[];if v002,v000=urlread(v001);else,v000=webread(v001,v006);end,catch v009;if ...
isempty(v009),v009=lasterror;end,error_(v003,v009),end,end,end
function[v000,v001,v002]=readfile_parse_inputs(v003,varargin),[v004,v005]=...
readfile_parse_inputs_defaults;[v000,v001,v002,v006,v007]=parse_varargin_robust(v004,...
varargin{:});if v006,return,end,[v008,v003]=filename_is_valid(v003);try v001.OfflineFile=~ ...
(strcmpi(v003(1:min(end,7)),'http://')||strcmpi(v003(1:min(end,8)),'https://'));if ...
v001.OfflineFile,if~exist(v003,'file'),v008=false;end,if~v008,error('trigger'),end,else,if ...
numel(v003)<10,error('trigger'),end,end,v001.filename=v003;catch,v002.identifier=...
'HJW:readfile:IncorrectInput';v002.message=...
'The file must exist and the name must be a non-empty char or a scalar string.';return,end,if ...
numel(v007)==0,v000=true;v002=[];return,end,for v009=1:numel(v007),v010=v001.(v007{v009});
v002.identifier=['HJW:readfile:incorrect_input_opt_' lower(v007{v009})];switch v007{v009},case ...
v005,case'UseURLread',[v011,v010]=test_if_scalar_logical(v010);if~v011,v002.message=...
'UseURLread should be either true or false';return,end,v001.UseURLread=v010||v004.UseURLread;
case'err_on_ANSI',[v011,v010]=test_if_scalar_logical(v010);if~v011,v002.message=...
'err_on_ANSI should be either true or false';return,end,v001.err_on_ANSI=v010;
case'EmptyLineRule',if isa(v010,'string'),if numel(v010)~=1,v010=[];else,v010=char(v010);end,...
end,if isa(v010,'char'),v010=lower(v010);end,if~isa(v010,'char')||~ismember(v010,{'read','skip',...
'error','skipleading','skiptrailing'}),v002.message=...
'EmptyLineRule must be a char or string with a specific value.';return,end,v001.EmptyLineRule=...
v010;case'Whitespace',try switch class(v010),case'string',if numel(v010)~=1,...
error('trigger error'),end,v010=char(v010);case'cell',for v012=1:numel(v010),v010{v012}=...
sprintf(v010{v012});end,v010=horzcat(v010{:});case'char',otherwise,error('trigger error'),end,...
v001.Whitespace=v010;catch,v002.message=...
['The Whitespace parameter must be a char vector, string scalar ',...
'or cellstr.\nA cellstr input must be parsable by sprintf.'];return,end,case'WhitespaceRule',if ...
isa(v010,'string'),if numel(v010)~=1,v010=[];else,v010=char(v010);end,end,if isa(v010,'char'),...
v010=lower(v010);end,if~isa(v010,'char')||~ismember(v010,{'preserve','trim','trimleading',...
'trimtrailing'}),v002.message='WhitespaceRule must be a char or string with a specific value.';
return,end,v001.WhitespaceRule=v010;case'LineEnding',v013=false;if isa(v010,'string'),v010=...
cellstr(v010);if numel(v010)==1,v010=v010{1};end,end,if isa(v010,'cell'),try for v012=...
1:numel(v010),v010{v012}=sprintf(v010{v012});end,catch,v013=true;end,elseif isa(v010,'char'),...
v010={v010};else,v013=true;end,if v013||~iscellstr(v010),v002.message=...
['The LineEnding parameter must be a char vector, a string or a ',...
'cellstr.\nA cellstr or string vector input must be parsable by sprintf.'];return,end,if ...
isequal(v010,{char(10) char(13) char([13 10])}),v001.LineEnding=[];else,v001.LineEnding=v010;
end,case'UseReadlinesDefaults',[v011,v010]=test_if_scalar_logical(v010);if~v011,v002.message=...
'UseReadlinesDefaults should be either true or false';return,end,v001.UseReadlinesDefaults=v010;
case'weboptions',if~v001.OfflineFile&&~v004.UseURLread,v014=false;if~isa(v010,...
class(weboptions)),v014=true;else,try v010.ContentType=v004.weboptions.ContentType;catch,v014=...
true;end,end,if v014,v002.message='weboptions input is not valid';return,end,end,end,end,if ...
v001.UseReadlinesDefaults,v015=fieldnames(v004.ReadlinesDefaults);for v012=1:numel(v015),...
v001.(v015{v012})=v004.ReadlinesDefaults.(v015{v012});end,end,v000=true;v002=[];end
function[v007,v008]=readfile_parse_inputs_defaults,persistent v000 v001,if isempty(v000),...
v002.allows_https=hasFeature('HTTPS_support');v000.legacy=v002;try v003=isempty(which(func2str(...
@webread)));catch,v003=true;end,try v004=isempty(which(func2str(@websave)));catch,v004=true;end,...
try v005=isempty(which(func2str(@weboptions)));catch,v005=true;end,v000.UseURLread=...
v003||v004||v005;[v000.print_to,v001]=parse_print_to___get_default;for v006=1:numel(v001),...
v000.(v001{v006})=[];end,v000.err_on_ANSI=false;v000.FailMultiword_UTF16=false;
v000.EmptyLineRule='read';v000.Whitespace=unicode_to_char([8 9 28:32 160 5760 8192:8202 8239 ...
8287 12288]);v000.DefaultLineEnding=true;v000.LineEnding=[];v000.WhitespaceRule='preserve';if ...
v005,v000.weboptions=struct('ContentType','raw');else,try v000.weboptions=...
weboptions('ContentType','raw');catch,v000.weboptions=weboptions('ContentType','text');end,end,...
v000.UseReadlinesDefaults=false;v000.ReadlinesDefaults.FailMultiword_UTF16=true;
v000.ReadlinesDefaults.Whitespace=sprintf(' \b\t');end,v007=v000;v008=v001;end
function v000=CharIsUTF8,persistent v001,if isempty(v001),if ifversion('<',0,'Octave','>',0),...
v002=struct('w',warning('off','all'));[v002.msg,v002.ID]=lastwarn;v001=~isequal(8364,...
double(char(8364)));warning(v002.w);lastwarn(v002.msg,v002.ID);else,v001=false;end,end,v000=...
v001;end
function v000=FindLiteralTextPositions(v001),v001=strrep(v001,'\"','__');v002=v001=='"';v003=...
cumsum(v002);v000=v002|mod(v003,2)~=0;end
function v000=TestFolderWritePermission(v001),if~(isempty(v001)||exist(v001,'dir')),v000=false;
return,end,v002='';while isempty(v002)||exist(v002,'file'),[v003,v002]=...
fileparts(tmpname('write_permission_test_','.txt'));v002=fullfile(v001,v002);end,try v004=...
fopen(v002,'w');fprintf(v004,'test');fclose(v004);delete(v002);v000=true;catch,if exist(v002,...
'file'),try delete(v002);catch,end,end,v000=false;end,end
function v000=unicode_to_UTF16(v001),if v001<65536,v000=v001;return,end,v002=double(v001)-65536;
v002=dec2bin(v002,20);v000=bin2dec(['110110' v002(1:10);'110111' v002(11:20)]).';end
function v000=tmpname(v001,v002),if nargin<1,v001='';end,if~isempty(v001),v001=[v001 '_'];end,...
if nargin<2,v002='';else,if~strcmp(v002(1),'.'),v002=['.' v002];end,end,v000=tempname;[v003,...
v004]=fileparts(v000);v000=fullfile(v003,[v001 v004 v002]);end
function v000=unicode_to_char(v001,v002),persistent v003,if isempty(v003),v003=ifversion('<',0,...
'Octave','>',0);end,if nargin==1,v002=~CharIsUTF8;end,if v002,if all(v001<65536),v000=...
uint16(v001);v000=reshape(v000,1,numel(v000));else,[v004,v005,v006]=unique(v001);v000=cell(1,...
numel(v001));for v007=1:numel(v004),v008=unicode_to_UTF16(v004(v007));v008=uint16(v008);
v000(v006==v007)={v008};end,v000=cell2mat(v000);end,if~v003,v000=char(v000);end,else,if ...
all(v001<128),v000=char(v001);v000=reshape(v000,1,numel(v000));else,[v004,v005,v006]=...
unique(v001);v000=cell(1,numel(v001));for v007=1:numel(v004),v008=unicode_to_UTF8(v004(v007));
v008=uint8(v008);v000(v006==v007)={v008};end,v000=cell2mat(v000);v000=char(v000);end,end,end
function[v000,v001]=PairBraces(v002),v000=zeros(size(v002));v003=v002=='{';v000(v003)=...
1:sum(v003);try v004=find(v003);for v005=find(v002=='}'),v006=find(v004<v005);v006=v006(end);
v007=v004(v006);v004(v006)=[];v000(v005)=-v000(v007);v003(v007)=false;end,if any(v003),...
error('trigger'),end,catch,v008='Unmatched braces found.';v009='PairBraces';throw_error(v008,...
v009),end,v003=v002=='[';v000(v003)=max(v000)+(1:sum(v003));try v004=find(v003);for v005=...
find(v002==']'),v006=find(v004<v005);v006=v006(end);v007=v004(v006);v004(v006)=[];v000(v005)=...
-v000(v007);v003(v007)=false;end,if any(v003),error('trigger'),end,catch,v008=...
'Unmatched braces found.';v009='PairBraces';throw_error(v008,v009),end,v001=false(1,...
numel(v002));v010=v002(ismember(double(v002),double('[{}]')));v011=v000(v000~=0);[v012,v013]=...
regexp(v010,'(\[)+\[');v013=v013-1;for v014=1:numel(v012);v001(v000==v011(v013(v014)))=true;end;
end
function v000=index(v000,v001),if numel(v001)==1,v001(2)=numel(v000.str);end,v001=...
v001(1):v001(2);v000.str=v000.str(v001);v000.s_tokens=v000.s_tokens(v001);v000.braces=...
v000.braces(v001);v000.ArrayOfArrays=v000.ArrayOfArrays(v001);end
function throw_error(msg,id),error(['HJW:JSON:' id],msg),end
function warning_(v001,varargin),persistent v000,if isempty(v000),v000=func2str(@warning_);end,...
if isempty(v001),v001=struct;end,v001=parse_warning_error_redirect_options(v001);[v002,v003,...
v004,v005,v006]=parse_warning_error_redirect_inputs(varargin{:});if v006,return,end,v007=...
warning;if any(ismember({v007(ismember({v007.identifier},{v002,'all'})).state},'off')),return,...
end,v008=warning('query','backtrace');if strcmp(v008.state,'off'),v005='';end,if ...
v001.params.ShowTraceInMessage&&~isempty(v005),v003=sprintf('%s\n%s',v003,v005);end,if ...
v001.params.WipeTraceForBuiltin&&strcmp(v008.state,'on'),warning('off','backtrace'),end,if ...
v001.boolean.con,v009=warning('query','verbose');if strcmp(v009.state,'on'),warning('off',...
'verbose'),end,if~isempty(v002),warning(v002,'%s',v003),else,warning(v003),end,if ...
strcmp(v009.state,'on'),warning('on','verbose'),end,else,if~isempty(v002),lastwarn(v003,v002);
else,lastwarn(v003),end,end,if v001.params.WipeTraceForBuiltin&&strcmp(v008.state,'on'),...
warning('on','backtrace'),end,if v001.boolean.obj,v010=v003;while v010(end)==10,v010(end)=[];
end,if any(v010==10),v010=char2cellstr(['Warning: ' v010]);else,v010=['Warning: ' v010];end,...
set(v001.obj,'String',v010),for v011=v001.obj(:).',try set(v011,'String',v010);catch,end,end,...
end,if v001.boolean.fid,v012=datestr(now,31);for v013=v001.fid(:).',try fprintf(v013,...
'[%s] Warning: %s\n%s',v012,v003,v005);catch,end,end,end,if v001.boolean.fcn,if ismember(v000,...
{v004.name}),error('prevent recursion'),end,v014=struct('identifier',v002,'message',v003,...
'stack',v004);for v015=v001.fcn(:).',if isfield(v015,'data'),try feval(v015.h,'warning',v014,...
v015.data);catch,end,else,try feval(v015.h,'warning',v014);catch,end,end,end,end,end