cleanBadChars Converts characters which are illegal in SBML to their entity reference strings a string or cell array %strings cleaned string or cell array The characters <>&'" are illegal in SBML (in most cases). They are here converted to their entity references. Empty or non-string cells are ignored. Usage: strings=cleanBadChars(strings) Rasmus Agren, 2013-08-03
0001 function strings=cleanBadChars(strings) 0002 % cleanBadChars 0003 % Converts characters which are illegal in SBML to their entity reference 0004 % 0005 % strings a string or cell array 0006 % 0007 % %strings cleaned string or cell array 0008 % 0009 % The characters <>&'" are illegal in SBML (in most cases). They are here 0010 % converted to their entity references. Empty or non-string cells are 0011 % ignored. 0012 % 0013 % Usage: strings=cleanBadChars(strings) 0014 % 0015 % Rasmus Agren, 2013-08-03 0016 % 0017 0018 %For simplicity 0019 wasChar=false; 0020 if ischar(strings) 0021 strings={strings}; 0022 wasChar=true; 0023 end 0024 0025 %Get the ids which are cell strings 0026 I=cellfun(@isstr,strings); 0027 0028 %Note that the order here matters 0029 strings(I)=strrep(strings(I),'&','&'); 0030 strings(I)=strrep(strings(I),'<','<'); 0031 strings(I)=strrep(strings(I),'>','>'); 0032 strings(I)=strrep(strings(I),'"','"'); 0033 strings(I)=strrep(strings(I),'''','''); 0034 strings(I)=strrep(strings(I),'%','%'); 0035 0036 if numel(strings)==1 && wasChar==true 0037 strings=strings{1}; 0038 end 0039 end