-
Notifications
You must be signed in to change notification settings - Fork 75
/
Copy pathsetjson.m
45 lines (42 loc) · 1.35 KB
/
setjson.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
function val = updatejson(fname, mmap, varargin)
if (isoctavemesh)
if (regexp(fname, '^\s*(?:\[.*\])|(?:\{.*\})\s*$', 'once'))
string = fname;
elseif (exist(fname, 'file'))
try
encoding = jsonopt('Encoding', '', opt);
if (isempty(encoding))
string = fileread(fname);
else
fid = fopen(fname, 'r', 'n', encoding);
string = fread(fid, '*char')';
fclose(fid);
end
catch
try
string = urlread(['file://', fname]);
catch
string = urlread(['file://', fullfile(pwd, fname)]);
end
end
else
error_pos('input file does not exist');
end
end
mmap = [mmap{:}];
keylist = mmap(1:2:end);
for i = 1:2:length(varargin)
if (regexp(varargin{i}, '^$'))
[tf, loc] = ismember(varargin{i}, keylist);
if (tf)
rec = {'uint8', [1, mmap{loc * 2}{1} - 1], 'o'; ...
'uint8', [1, mmap{loc * 2}{2}], 'x'};
fmap = memmapfile(fname, 'writable', true, 'format', rec);
val = savejson('', varargin{i + 1}, 'compact', 1);
if (length(var) <= rec{2, 2}{2})
val = [val repmat(' ', [1, rec{2, 2}{2} - length(var)])];
fmap.x = val;
end
end
end
end