function str=ASCII_decode(str)
% Convert '&#___;' back to char (including the hexadecimal '&#x___;').
%
%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%/%
%|                                                                         |%
%|  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 isa(str,'char'),str=reshape(str,1,[]);end,v001=...
warning('off','REGEXP:multibyteCharacters');if isempty(regexp(str,'&#\d+;',...
'once'))&&isempty(regexp(str,'&#x[0-9A-Fa-f]+;','once')),warning(v001);return,end,...
if~isempty(regexp(str,'&#x[0-9A-Fa-f]+;','once')),v002=regexp_outkeys(str,'&#x[0-9A-Fa-f]+;',...
'match');v002=unique(v002);for v003=1:numel(v002),str=strrep(str,v002{v003},sprintf('&#%d;',...
hex2dec(v002{v003}(4:(end-1)))));end,end,[v004,v005]=regexp_outkeys(str,'&#\d+;','match',...
'split');v002=unique(v004);v004{end+1}='';v006=[v005;v004];v006=v006(:).';for v003=...
1:numel(v002),v007=str2double(v002{v003}(3:(end-1)));if CharIsUTF8,v008=unicode_to_UTF8(v007);
else,v008=unicode_to_UTF16(v007);end,v006(ismember(v006,v002{v003}))={char(v008)};end,str=...
cell2mat(v006);warning(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=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 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=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=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