Skip to content

Commit

Permalink
unescape string in fast array parser mode
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed May 6, 2019
1 parent 30a842e commit 25ad795
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion loadjson.m
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@
arraystr=regexprep(arraystr,'\"','''');
end
object=eval(arraystr);
if(iscell(object))
object=cellfun(@unescapejsonstring,object,'UniformOutput',false);
end
pos=endpos;
catch
while 1
Expand Down Expand Up @@ -510,8 +513,11 @@ function error_pos(msg, inStr)

function newstr=unescapejsonstring(str)
newstr=str;
if(~ischar(str))
return;
end
escapechars={'\\','\"','\/','\a','\b','\f','\n','\r','\t','\v'};
for i=1:length(escapechars);
newstr=regexprep(newstr,regexprep(escapechars{i},'\\','\\\\'), escapechars{i});
end
newstr=regexprep(newstr,'\\\\(u[0-9a-fA-F]{4}[^0-9a-fA-F]*)','\\$1');
newstr=regexprep(newstr,'\\u([0-9A-Fa-f]{4})', '${char(base2dec($1,16))}');

0 comments on commit 25ad795

Please sign in to comment.