|
171 | 171 |
|
172 | 172 | if (strcmp(idx.type, '.') && isnumeric(idx.subs)) |
173 | 173 | val = val(idx.subs); |
174 | | - elseif ((strcmp(idx.type, '()') || strcmp(idx.type, '.')) && ischar(idx.subs) && ismember(idx.subs, {'tojson', 'fromjson', 'v', 'keys', 'len', 'setattr', 'getattr'}) && i < oplen) |
| 174 | + elseif ((strcmp(idx.type, '()') || strcmp(idx.type, '.')) && ischar(idx.subs) && ismember(idx.subs, {'tojson', 'fromjson', 'v', 'keys', 'len', 'size', 'setattr', 'getattr'}) && i < oplen) |
175 | 175 | if (strcmp(idx.subs, 'v')) |
176 | 176 | if (iscell(val) && strcmp(idxkey(i + 1).type, '()')) |
177 | 177 | idxkey(i + 1).type = '{}'; |
|
278 | 278 | return |
279 | 279 | elseif (~(isempty(idxkey(end).subs) && (strcmp(idxkey(end).type, '()') || strcmp(idxkey(end).type, '{}')))) |
280 | 280 | newobj = jdict(val); |
281 | | - newobj.attr = obj.attr; |
282 | | - newobj.currentpath = trackpath; |
| 281 | + attrkeys = keys(obj.attr); |
| 282 | + newobj.attr = containers.Map(); |
| 283 | + for i = 1:length(attrkeys) |
| 284 | + if (strncmp(attrkeys{i}, trackpath, length(trackpath))) |
| 285 | + newobj.attr(strrep(attrkeys{i}, trackpath, char(36))) = obj.attr(attrkeys{i}); |
| 286 | + end |
| 287 | + end |
| 288 | + newobj.currentpath = char(36); |
283 | 289 | val = newobj; |
284 | 290 | end |
285 | 291 | varargout{1} = val; |
|
418 | 424 | idx.type = '()'; |
419 | 425 | opcell{i}(idx.subs) = obj.newkey_(); |
420 | 426 | elseif (isstruct(opcell{i}) && ~isfield(opcell{i}, idx.subs)) |
421 | | - opcell{i}.(idx.subs) = obj.newkey_(); |
| 427 | + try |
| 428 | + opcell{i}.(idx.subs) = obj.newkey_(); |
| 429 | + catch |
| 430 | + opcell{i} = containers.Map(fieldnames(opcell{i}), struct2cell(opcell{i})); |
| 431 | + opcell{i}(idx.subs) = obj.newkey_(); |
| 432 | + end |
422 | 433 | end |
423 | 434 | end |
424 | 435 | end |
|
433 | 444 | opcell{i}(idx.subs) = otherobj; |
434 | 445 | opcell{end - 1} = opcell{i}; |
435 | 446 | else |
| 447 | + if (isa(opcell{i}, 'containers.Map') || isa(opcell{i}, 'dictionary')) |
| 448 | + idx = struct('type', '()', 'subs', idx.subs); |
| 449 | + end |
436 | 450 | opcell{end - 1} = subsasgn(opcell{i}, idx, otherobj); |
437 | 451 | end |
438 | 452 |
|
|
485 | 499 |
|
486 | 500 | function val = len(obj) |
487 | 501 | % return the number of subfields at the current level |
488 | | - val = length(obj.data); |
| 502 | + if (isstruct(obj.data)) |
| 503 | + val = length(fieldnames(obj.data)); |
| 504 | + else |
| 505 | + val = length(obj.data); |
| 506 | + end |
| 507 | + end |
| 508 | + |
| 509 | + function val = size(obj) |
| 510 | + % return the dimension vector of the data |
| 511 | + val = size(obj.data); |
489 | 512 | end |
490 | 513 |
|
491 | 514 | function val = v(obj, varargin) |
|
544 | 567 | end |
545 | 568 |
|
546 | 569 | function val = getattr(obj, jsonpath, attrname) |
| 570 | + if (nargin == 1) |
| 571 | + val = keys(obj.attr); |
| 572 | + return |
| 573 | + end |
547 | 574 | if (nargin == 2) |
548 | 575 | attrname = jsonpath; |
549 | 576 | jsonpath = obj.currentpath; |
|
0 commit comments