|
83 | 83 | end
|
84 | 84 |
|
85 | 85 | pos = 1; len = length(string); inputstr = string;
|
86 |
| -arraytoken=find(inputstr=='[' | inputstr==']' | inputstr=='"'); |
87 |
| -jstr=regexprep(inputstr,'\\\\',' '); |
88 |
| -escquote=regexp(jstr,'\\"'); |
89 |
| -arraytoken=sort([arraytoken escquote]); |
| 86 | +arraytokenidx=find(inputstr=='[' | inputstr==']'); |
| 87 | +arraytoken=inputstr(arraytokenidx); |
90 | 88 |
|
91 | 89 | % String delimiters and escape chars identified to improve speed:
|
92 | 90 | esc = find(inputstr=='"' | inputstr=='\' ); % comparable to: regexp(inputstr, '["\\]');
|
93 | 91 | index_esc = 1;
|
94 | 92 |
|
95 | 93 | opt=varargin2struct(varargin{:});
|
96 | 94 | opt.arraytoken_=arraytoken;
|
| 95 | +opt.arraytokenidx_=arraytokenidx; |
97 | 96 |
|
98 | 97 | if(jsonopt('ShowProgress',0,opt)==1)
|
99 | 98 | opt.progressbar_=waitbar(0,'loading ...');
|
|
159 | 158 | if next_char(inputstr) ~= ']'
|
160 | 159 | try
|
161 | 160 | if(jsonopt('FastArrayParser',1,varargin{:})>=1 && arraydepth>=jsonopt('FastArrayParser',1,varargin{:}))
|
162 |
| - [endpos, maxlevel]=match_bracket(inputstr,pos); |
| 161 | + [endpos, maxlevel]=fast_match_bracket(varargin{1}.arraytoken_,varargin{1}.arraytokenidx_,pos); |
163 | 162 | if(~isempty(endpos))
|
164 | 163 | arraystr=['[' inputstr(pos:endpos)];
|
165 | 164 | arraystr=sscanf_prep(arraystr);
|
|
218 | 217 | end
|
219 | 218 | end
|
220 | 219 | end
|
221 |
| - if(regexp(arraystr,':','once')) |
222 |
| - error('One can not use ":" construct inside a JSON array'); |
223 |
| - end |
224 |
| - arraystr=regexprep(arraystr,'\[','{'); |
225 |
| - arraystr=regexprep(arraystr,'\]','}'); |
226 |
| - if(jsonopt('ParseStringArray',0,varargin{:})==0) |
227 |
| - arraystr=regexprep(arraystr,'\"',''''); |
228 |
| - end |
229 |
| - object=eval(arraystr); |
230 |
| - if(iscell(object)) |
231 |
| - object=cellfun(@unescapejsonstring,object,'UniformOutput',false); |
| 220 | + if(isempty(regexp(arraystr,':','once'))) |
| 221 | + arraystr=regexprep(arraystr,'\[','{'); |
| 222 | + arraystr=regexprep(arraystr,'\]','}'); |
| 223 | + if(jsonopt('ParseStringArray',0,varargin{:})==0) |
| 224 | + arraystr=regexprep(arraystr,'\"',''''); |
| 225 | + end |
| 226 | + object=eval(arraystr); |
| 227 | + if(iscell(object)) |
| 228 | + object=cellfun(@unescapejsonstring,object,'UniformOutput',false); |
| 229 | + end |
| 230 | + pos=endpos; |
232 | 231 | end
|
233 |
| - pos=endpos; |
234 | 232 | catch
|
235 |
| - while 1 |
| 233 | + end |
| 234 | + if(pos~=endpos) |
| 235 | + while 1 |
236 | 236 | newopt=varargin2struct(varargin{:},'JSONLAB_ArrayDepth_',arraydepth+1);
|
237 | 237 | val = parse_value(inputstr, esc, newopt);
|
238 | 238 | object{end+1} = val;
|
239 | 239 | if next_char(inputstr) == ']'
|
240 | 240 | break;
|
241 | 241 | end
|
242 | 242 | parse_char(inputstr, ',');
|
243 |
| - end |
| 243 | + end |
244 | 244 | end
|
245 | 245 | end
|
246 | 246 |
|
@@ -436,15 +436,14 @@ function error_pos(msg, inputstr)
|
436 | 436 | % Invalid characters will be converted to underscores, and the prefix
|
437 | 437 | % "x0x[Hex code]_" will be added if the first character is not a letter.
|
438 | 438 | isoct=exist('OCTAVE_VERSION','builtin');
|
439 |
| - pos=regexp(str,'^[^A-Za-z]','once'); |
440 |
| - if(~isempty(pos)) |
| 439 | + if(~isvarname(str)) |
441 | 440 | if(~isoct && str(1)+0 > 255)
|
442 | 441 | str=regexprep(str,'^([^A-Za-z])','x0x${sprintf(''%X'',unicode2native($1))}_','once');
|
443 | 442 | else
|
444 | 443 | str=sprintf('x0x%X_%s',char(str(1)),str(2:end));
|
445 | 444 | end
|
446 | 445 | end
|
447 |
| - if(isempty(regexp(str,'[^0-9A-Za-z_]', 'once' ))) |
| 446 | + if(isvarname(str)) |
448 | 447 | return;
|
449 | 448 | end
|
450 | 449 | if(~isoct)
|
|
0 commit comments