Skip to content

Commit

Permalink
skil no-op markers, update documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Jun 13, 2020
1 parent 4904155 commit 81feef3
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 19 deletions.
1 change: 1 addition & 0 deletions ChangeLog.txt
Expand Up @@ -8,6 +8,7 @@ JSONlab ChangeLog (key features marked by *):

== JSONlab 2.0 (codename: Magnus Prime), FangQ <q.fang (at) neu.edu> ==

2020-06-09*[ ] created `jdata` and `bjdata` python modules to share data with MATLAB
2020-06-08*[cbde607] add savebj and loadbj to dedicate to loading and saving bjdata
2020-06-08*[e2451e1] add unit testing script, fix issues found in the testing unit
2020-06-06 [a44015f] accelerate fast_match_bracket, drop unicode2native for speed
Expand Down
23 changes: 13 additions & 10 deletions Contents.m
Expand Up @@ -12,7 +12,7 @@
% jdatadecode - newdata=jdatadecode(data,opt,...)
% jdataencode - jdata=jdataencode(data)
% jsave - jsave(fname,'param1',value1,'param2',value2,...)
% jload - jload(fname,'param1',value1,'param2',value2,...)
% jload - vars=jload(fname,'param1',value1,'param2',value2,...)
% jsonopt - val=jsonopt(key,default,optstruct)
% loadbj - data=loadbj(fname,opt)
% loadjson - data=loadjson(fname,opt)
Expand Down Expand Up @@ -726,21 +726,21 @@
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% ws ['base'|'wsname']: the name of the workspace in which the
% ws ['caller'|'base']: the name of the workspace in which the
% variables are to be saved
% vars [{'var1','var2',...}]: cell array of variable names to be saved
% matlab [0|1] if set to 1, use matlab's built-in jsonencode to
% store encoded data to a json file; output file
% must have a suffix of .jdt
%
% all options for saveubjson/savejson (depends on file suffix)
% all options for savebj/savejson (depends on file suffix)
% can be used to adjust the output unless "'matlab',1" is used
%
% output:
% varlist: a list of variables loaded
%
% examples:
% jsave % save all variables in the 'base' workspace to jamdata.jamm
% jsave % save all variables in the 'caller' workspace to jamdata.jamm
% jsave('mydat.jamm','vars', {'v1','v2',...}) % save selected variables
% jsave('mydat.jamm','compression','lzma')
%
Expand All @@ -753,6 +753,8 @@
% jload
% or
% jload(fname)
% varlist=jload(fname)
% [varlist, header]=jload(fname)
% varlist=jload(fname,'param1',value1,'param2',value2,...)
%
% Load variables from a JSON or binary JSON file to a workspace
Expand All @@ -769,7 +771,7 @@
% to a field in opt. opt can have the following
% fields (first in [.|.] is the default)
%
% ws ['base'|'wsname']: the name of the workspace in which the
% ws ['caller'|'base']: the name of the workspace in which the
% variables are to be saved
% vars [{'var1','var2',...}]: list of variables to be saved
% header [0|1]: if set to 1, return the metadata of the variables
Expand All @@ -782,13 +784,16 @@
% can be used to adjust the parsing options
%
% output:
% varlist: a list of variables loaded
% varlist: a struct with each subfield a variable stored in the file,
% if output is ignored, the variables will be loaded to the
% workspace specified by the 'ws' option, which by default
% load the variables to the current workspace ('caller')
%
% examples:
% jload % load all variables in jamdata.jamm to the 'base' workspace
% jload % load all variables in jamdata.jamm to the 'caller' workspace
% jload mydat.jamm
% jload('mydat.jamm','vars', {'v1','v2',...}) % load selected variables
% jload('mydat.jamm','simplifycell',1)
% varlist=jload('mydat.jamm','simplifycell',1)
%
% license:
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
Expand Down Expand Up @@ -1425,5 +1430,3 @@
% license:
% BSD or GPL version 3, see LICENSE_{BSD,GPLv3}.txt files for details
%


2 changes: 1 addition & 1 deletion DESCRIPTION
@@ -1,6 +1,6 @@
Name: jsonlab
Version: 2.0.0
Date: 2020-06-01
Date: 2020-06-13

Title: A JSON/UBJSON/MessagePack encoder/decoder for MATLAB/Octave
Author: Qianqian Fang <fangqq@gmail.com>
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Expand Up @@ -380,8 +380,8 @@ jload.m
.. code-block:: matlab
jload % load variables from jamdata.jamm to the current workspace
jload mydata.jamm
jload('mydata.jamm','vars',{'var1','var2'})
jload mydata.jamm % load variables from mydata.jamm
vars=jload('mydata.jamm','vars',{'var1','var2'}) % return vars.var1, vars.var2
jload('mydata.jamm','simplifycell',0)
jload('mydata.json')
Expand Down
4 changes: 2 additions & 2 deletions README.txt
Expand Up @@ -334,8 +334,8 @@ The main benefits of using .jamm file to share matlab variables include
=== jload.m ===

jload % load variables from jamdata.jamm to the current workspace
jload mydata.jamm
jload('mydata.jamm','vars',{'var1','var2'})
jload mydata.jamm % load variables from mydata.jamm
vars=jload('mydata.jamm','vars',{'var1','var2'}) % return vars.var1, vars.var2
jload('mydata.jamm','simplifycell',0)
jload('mydata.json')

Expand Down
7 changes: 6 additions & 1 deletion loadbj.m
Expand Up @@ -244,6 +244,10 @@
c = [];
else
c = inputstr(pos);
while(c=='N')
pos=pos+1;
c = inputstr(pos);
end
end
end

Expand Down Expand Up @@ -307,7 +311,8 @@
%%-------------------------------------------------------------------------

function [val, pos] = parse_value(inputstr, pos, varargin)
switch(inputstr(pos))
[cc,pos]=next_char(inputstr,pos);
switch(cc)
case {'S','C','H'}
[val, pos] = parseStr(inputstr, pos, varargin{:});
return;
Expand Down
6 changes: 3 additions & 3 deletions saveubjson.m
Expand Up @@ -63,9 +63,9 @@
%

if(nargin==1)
ubj=saveubjson('',rootname,'ubjson',1);
ubj=savebj('',rootname,'ubjson',1);
elseif(length(varargin)==1 && ischar(varargin{1}))
ubj=saveubjson(rootname,obj,'FileName',varargin{1},'ubjson',1);
ubj=savebj(rootname,obj,'FileName',varargin{1},'ubjson',1);
else
ubj=saveubjson(rootname,obj,varargin{:},'ubjson',1);
ubj=savebj(rootname,obj,varargin{:},'ubjson',1);
end
1 change: 1 addition & 0 deletions test/run_jsonlab_test.m
Expand Up @@ -171,6 +171,7 @@ function run_jsonlab_test(tests)
test_jsonlab('empty array',@savebj,[],'Z','debug',1);
test_jsonlab('empty cell',@savebj,{},'Z','debug',1);
test_jsonlab('empty string',@savebj,'','SU<0>','debug',1);
test_jsonlab('skip no-op before marker and after value',@savebj,loadbj(char(['NN[NU' char(5) 'NNNU' char(1) ']'])),'[$U#U<2><5><1>','debug',1);
test_jsonlab('string escape',@savebj,sprintf('jdata\n\b\ashall\tprevail\t"\"\\'),sprintf('SU<25>jdata\n\b\ashall\tprevail\t\"\"\\'),'debug',1);
if(exist('isstring'))
test_jsonlab('string type',@savebj,string(sprintf('jdata\n\b\ashall\tprevail')),sprintf('[SU<21>jdata\n\b\ashall\tprevail]'),'debug',1);
Expand Down

0 comments on commit 81feef3

Please sign in to comment.