Skip to content

Commit

Permalink
disable underscore escaping in octave,update all tests and outputs
Browse files Browse the repository at this point in the history
  • Loading branch information
fangq committed Oct 24, 2019
1 parent d4275c6 commit ad8be26
Show file tree
Hide file tree
Showing 14 changed files with 170 additions and 92 deletions.
19 changes: 12 additions & 7 deletions Contents.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
% Serialize a MATLAB struct or cell array into a JData-compliant
% structure as defined in the JData spec: http:/fangq/jdata
%
% This function implements the JData Specification Draft 2a (Oct. 2019)
% This function implements the JData Specification Draft 2 (Oct. 2019)
% see http:/fangq/jdata for details
%
%
Expand All @@ -58,9 +58,11 @@
% decoded first. This is needed for JSON but not
% UBJSON data
% Prefix: ['x0x5F'|'x'] for JData files loaded via loadjson/loadubjson, the
% default JData keyword prefix is 'x0x5F'(default);
% if the json file is loaded using matlab2018's
% jsondecode(), the prefix is 'x'.
% default JData keyword prefix is 'x0x5F'; if the
% json file is loaded using matlab2018's
% jsondecode(), the prefix is 'x'; this function
% attempts to automatically determine the prefix;
% for octave, the default value is an empty string ''.
% UseArrayZipSize: [1|0] if set to 1, _ArrayZipSize_ will be added to
% store the "pre-processed" data dimensions, i.e.
% the original data stored in _ArrayData_, and then flaten
Expand Down Expand Up @@ -93,7 +95,7 @@
% (accepts JData objects loaded from either loadjson/loadubjson or
% jsondecode for MATLAB R2018a or later)
%
% This function implements the JData Specification Draft 2a (Oct. 2019)
% This function implements the JData Specification Draft 2 (Oct. 2019)
% see http:/fangq/jdata for details
%
%
Expand All @@ -117,7 +119,8 @@
% default JData keyword prefix is 'x0x5F'; if the
% json file is loaded using matlab2018's
% jsondecode(), the prefix is 'x'; this function
% attempts to automatically determine the prefix.
% attempts to automatically determine the prefix;
% for octave, the default value is an empty string ''.
% FormatVersion: [2|float]: set the JSONLab output version;
% since v2.0, JSONLab uses JData specification Draft 1
% for output format, it is incompatible with all
Expand Down Expand Up @@ -236,6 +239,8 @@
% FileName [''|string]: a file name to save the output JSON data
% FloatFormat ['%.10g'|string]: format to show each numeric element
% of a 1D/2D array;
% IntFormat ['%d'|string]: format to display integer elements
% of a 1D/2D array;
% ArrayIndent [1|0]: if 1, output explicit data array with
% precedent indentation; if 0, no indentation
% ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
Expand Down Expand Up @@ -982,7 +987,7 @@
% newname: the restored original string
%
% example:
% decodevarname('x0x5F_a) % returns _a
% decodevarname('x0x5F_a') % returns _a
% decodevarname('a_') % returns a_ as it is a valid variable name
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
%
Expand Down
6 changes: 3 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
* License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt
* Version: 1.9.8 (Magnus - beta)
* JData Specification Version: Draft 2a (http:/fangq/jdata)
* JData Specification Version: Draft 2 (http:/fangq/jdata)
* URL: http://openjdata.org/jsonlab


Expand All @@ -25,7 +25,7 @@ JSONLab v1.9.8 is the beta release of the next milestone - code named "Magnus".
Starting from this release, JSONLab supports encoding/decoding MessagePack,
a widely-used binary JSON-like data format. Via ZMat v0.9, JSONLab v1.9.8
also supports LZMA/LZ4/LZ4HC data compression/decompression. More importantly,
JSONLab is now the official reference implementation for JData Specification (Draft 2a)
JSONLab is now the official reference implementation for JData Specification (Draft 2)
as defined in http:/fangq/jdata, the foundation for the OpenJData
Project (http://openjdata.org).

Expand Down Expand Up @@ -55,7 +55,7 @@ with key features marked by *:
- 2019-05-19*[c87e7d2] support containers.Map


Please note that JSONLab v1.9.8 is compliant with JData Spec Draft 2a, while
Please note that JSONLab v1.9.8 is compliant with JData Spec Draft 2, while
v1.9 and previous releases are compatible with Draft 1. The main differences are

* ``_ArrayCompressionMethod_, _ArrayCompressionSize_`` and ``_ArrayCompressedData_``
Expand Down
6 changes: 3 additions & 3 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
* License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt
* Version: 1.9.8 (Magnus - beta)
* JData Specification Version: Draft 2a (http:/fangq/jdata)
* JData Specification Version: Draft 2 (http:/fangq/jdata)
* URL: http://openjdata.org/jsonlab

-------------------------------------------------------------------------------
Expand All @@ -30,7 +30,7 @@ JSONLab v1.9.8 is the beta release of the next milestone - code named "Magnus".
Starting from this release, JSONLab supports encoding/decoding MessagePack,
a widely-used binary JSON-like data format. Via ZMat v0.9, JSONLab v1.9.8
also supports LZMA/LZ4/LZ4HC data compression/decompression. More importantly,
JSONLab is now the official reference implementation for JData Specification (Draft 2a)
JSONLab is now the official reference implementation for JData Specification (Draft 2)
as defined in http:/fangq/jdata, the foundation for the OpenJData
Project (http://openjdata.org).

Expand Down Expand Up @@ -60,7 +60,7 @@ with key features marked by *:
* 2019-05-19*[c87e7d2] support containers.Map


Please note that JSONLab v1.9.8 is compliant with JData Spec Draft 2a, while
Please note that JSONLab v1.9.8 is compliant with JData Spec Draft 2, while
v1.9 and previous releases are compatible with Draft 1. The main differences are

* _ArrayCompressionMethod_, _ArrayCompressionSize_</tt> and <tt>_ArrayCompressedData_</tt> \
Expand Down
2 changes: 1 addition & 1 deletion decodevarname.m
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
% newname: the restored original string
%
% example:
% decodevarname('x0x5F_a) % returns _a
% decodevarname('x0x5F_a') % returns _a
% decodevarname('a_') % returns a_ as it is a valid variable name
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
%
Expand Down
50 changes: 42 additions & 8 deletions examples/demo_jsonlab_basic.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@
data2json=1:3
savejson('',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a simple column vector \n')
Expand All @@ -45,6 +48,9 @@
data2json=(1:3)'
savejson('',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a string array \n')
Expand All @@ -69,6 +75,9 @@
data2json={'a',true,[2;3]}
savejson('',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a 3-D array in nested array form\n')
Expand All @@ -77,7 +86,7 @@
data2json=reshape(1:(2*4*6),[2,4,6]);
savejson('',data2json,'NestArray',1)
json2data=loadjson(ans)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

Expand All @@ -88,7 +97,7 @@
data2json=reshape(1:(2*4*6),[2,4,6]);
savejson('',data2json,'NestArray',0)
json2data=loadjson(ans)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

Expand All @@ -99,7 +108,7 @@
data2json=reshape(1:(2*4*3*2),[2,4,3,2]);
savejson('',data2json,'NestArray',0) % nestarray for 4-D or above is not working
json2data=loadjson(ans)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

Expand All @@ -110,7 +119,7 @@
data2json=reshape(1:(2*4*6),[2,4,6]);
savejson('',data2json,'NestArray',1,'FormatVersion',1.8)
json2data=loadjson(ans,'FormatVersion',1.8)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

Expand All @@ -121,7 +130,7 @@
data2json=reshape(1:(2*4*6),[2,4,6]);
savejson('',data2json,'NestArray',0,'FormatVersion',1.8)
json2data=loadjson(ans,'FormatVersion',1.8)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

Expand All @@ -132,6 +141,9 @@
data2json=1+2i
savejson('',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex matrix\n')
Expand All @@ -141,6 +153,9 @@
data2json=data2json(:,1:3)+data2json(:,4:6)*1i
savejson('',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% MATLAB special constants\n')
Expand All @@ -149,22 +164,32 @@
data2json=[NaN Inf -Inf]
savejson('specials',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data.specials,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a real sparse matrix\n')
fprintf(1,'%%=================================================\n\n')

data2json=sprand(10,10,0.1)
savejson('sparse',data2json)
savejson('sparse',data2json,'FloatFormat','%.18g')
json2data=loadjson(ans)
if(~isequaln(json2data.sparse,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a complex sparse matrix\n')
fprintf(1,'%%=================================================\n\n')

data2json=sprand(10,10,0.1);
data2json=data2json-data2json*1i
savejson('complex_sparse',data2json)
savejson('complex_sparse',data2json,'FloatFormat','%.18g')
json2data=loadjson(ans)
if(~isequaln(json2data.complex_sparse,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an all-zero sparse matrix\n')
Expand All @@ -173,6 +198,9 @@
data2json=sparse(2,3);
savejson('all_zero_sparse',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data.all_zero_sparse,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty sparse matrix\n')
Expand All @@ -181,6 +209,9 @@
data2json=sparse([]);
savejson('empty_sparse',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data.empty_sparse,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% an empty 0-by-0 real matrix\n')
Expand All @@ -197,6 +228,9 @@
data2json=zeros(0,3);
savejson('empty_0by3_real',data2json)
json2data=loadjson(ans)
if(~isequaln(json2data.empty_0by3_real,data2json))
warning('conversion does not preserve original data');
end

fprintf(1,'\n%%=================================================\n')
fprintf(1,'%% a sparse real column vector\n')
Expand Down Expand Up @@ -338,7 +372,7 @@
data2json(20,1)=1;
savejson('',data2json,'Compression','zlib','CompressionSize',0) % nestarray for 4-D or above is not working
json2data=loadjson(ans)
if(any(json2data(:)~=data2json(:)) || any(size(json2data)~=size(data2json)))
if(~isequaln(json2data,data2json))
warning('conversion does not preserve original data');
end
catch
Expand Down
Loading

0 comments on commit ad8be26

Please sign in to comment.