Skip to content

Commit ad8be26

Browse files
committed
disable underscore escaping in octave,update all tests and outputs
1 parent d4275c6 commit ad8be26

14 files changed

+170
-92
lines changed

Contents.m

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
% Serialize a MATLAB struct or cell array into a JData-compliant
4646
% structure as defined in the JData spec: http://github.com/fangq/jdata
4747
%
48-
% This function implements the JData Specification Draft 2a (Oct. 2019)
48+
% This function implements the JData Specification Draft 2 (Oct. 2019)
4949
% see http://github.com/fangq/jdata for details
5050
%
5151
%
@@ -58,9 +58,11 @@
5858
% decoded first. This is needed for JSON but not
5959
% UBJSON data
6060
% Prefix: ['x0x5F'|'x'] for JData files loaded via loadjson/loadubjson, the
61-
% default JData keyword prefix is 'x0x5F'(default);
62-
% if the json file is loaded using matlab2018's
63-
% jsondecode(), the prefix is 'x'.
61+
% default JData keyword prefix is 'x0x5F'; if the
62+
% json file is loaded using matlab2018's
63+
% jsondecode(), the prefix is 'x'; this function
64+
% attempts to automatically determine the prefix;
65+
% for octave, the default value is an empty string ''.
6466
% UseArrayZipSize: [1|0] if set to 1, _ArrayZipSize_ will be added to
6567
% store the "pre-processed" data dimensions, i.e.
6668
% the original data stored in _ArrayData_, and then flaten
@@ -93,7 +95,7 @@
9395
% (accepts JData objects loaded from either loadjson/loadubjson or
9496
% jsondecode for MATLAB R2018a or later)
9597
%
96-
% This function implements the JData Specification Draft 2a (Oct. 2019)
98+
% This function implements the JData Specification Draft 2 (Oct. 2019)
9799
% see http://github.com/fangq/jdata for details
98100
%
99101
%
@@ -117,7 +119,8 @@
117119
% default JData keyword prefix is 'x0x5F'; if the
118120
% json file is loaded using matlab2018's
119121
% jsondecode(), the prefix is 'x'; this function
120-
% attempts to automatically determine the prefix.
122+
% attempts to automatically determine the prefix;
123+
% for octave, the default value is an empty string ''.
121124
% FormatVersion: [2|float]: set the JSONLab output version;
122125
% since v2.0, JSONLab uses JData specification Draft 1
123126
% for output format, it is incompatible with all
@@ -236,6 +239,8 @@
236239
% FileName [''|string]: a file name to save the output JSON data
237240
% FloatFormat ['%.10g'|string]: format to show each numeric element
238241
% of a 1D/2D array;
242+
% IntFormat ['%d'|string]: format to display integer elements
243+
% of a 1D/2D array;
239244
% ArrayIndent [1|0]: if 1, output explicit data array with
240245
% precedent indentation; if 0, no indentation
241246
% ArrayToStruct[0|1]: when set to 0, savejson outputs 1D/2D
@@ -982,7 +987,7 @@
982987
% newname: the restored original string
983988
%
984989
% example:
985-
% decodevarname('x0x5F_a) % returns _a
990+
% decodevarname('x0x5F_a') % returns _a
986991
% decodevarname('a_') % returns a_ as it is a valid variable name
987992
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
988993
%

README.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
66
* License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt
77
* Version: 1.9.8 (Magnus - beta)
8-
* JData Specification Version: Draft 2a (http://github.com/fangq/jdata)
8+
* JData Specification Version: Draft 2 (http://github.com/fangq/jdata)
99
* URL: http://openjdata.org/jsonlab
1010

1111

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

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

5757

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

6161
* ``_ArrayCompressionMethod_, _ArrayCompressionSize_`` and ``_ArrayCompressedData_``

README.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
* Copyright (C) 2011-2019 Qianqian Fang <q.fang at neu.edu>
77
* License: BSD or GNU General Public License version 3 (GPL v3), see License*.txt
88
* Version: 1.9.8 (Magnus - beta)
9-
* JData Specification Version: Draft 2a (http://github.com/fangq/jdata)
9+
* JData Specification Version: Draft 2 (http://github.com/fangq/jdata)
1010
* URL: http://openjdata.org/jsonlab
1111

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

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

6262

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

6666
* _ArrayCompressionMethod_, _ArrayCompressionSize_</tt> and <tt>_ArrayCompressedData_</tt> \

decodevarname.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
% newname: the restored original string
2222
%
2323
% example:
24-
% decodevarname('x0x5F_a) % returns _a
24+
% decodevarname('x0x5F_a') % returns _a
2525
% decodevarname('a_') % returns a_ as it is a valid variable name
2626
% decodevarname('x0xE58F98__0xE9878F_') % returns '变量'
2727
%

examples/demo_jsonlab_basic.m

Lines changed: 42 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
data2json=1:3
3838
savejson('',data2json)
3939
json2data=loadjson(ans)
40+
if(~isequaln(json2data,data2json))
41+
warning('conversion does not preserve original data');
42+
end
4043

4144
fprintf(1,'\n%%=================================================\n')
4245
fprintf(1,'%% a simple column vector \n')
@@ -45,6 +48,9 @@
4548
data2json=(1:3)'
4649
savejson('',data2json)
4750
json2data=loadjson(ans)
51+
if(~isequaln(json2data,data2json))
52+
warning('conversion does not preserve original data');
53+
end
4854

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

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

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

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

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

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

@@ -132,6 +141,9 @@
132141
data2json=1+2i
133142
savejson('',data2json)
134143
json2data=loadjson(ans)
144+
if(~isequaln(json2data,data2json))
145+
warning('conversion does not preserve original data');
146+
end
135147

136148
fprintf(1,'\n%%=================================================\n')
137149
fprintf(1,'%% a complex matrix\n')
@@ -141,6 +153,9 @@
141153
data2json=data2json(:,1:3)+data2json(:,4:6)*1i
142154
savejson('',data2json)
143155
json2data=loadjson(ans)
156+
if(~isequaln(json2data,data2json))
157+
warning('conversion does not preserve original data');
158+
end
144159

145160
fprintf(1,'\n%%=================================================\n')
146161
fprintf(1,'%% MATLAB special constants\n')
@@ -149,22 +164,32 @@
149164
data2json=[NaN Inf -Inf]
150165
savejson('specials',data2json)
151166
json2data=loadjson(ans)
167+
if(~isequaln(json2data.specials,data2json))
168+
warning('conversion does not preserve original data');
169+
end
152170

153171
fprintf(1,'\n%%=================================================\n')
154172
fprintf(1,'%% a real sparse matrix\n')
155173
fprintf(1,'%%=================================================\n\n')
156174

157175
data2json=sprand(10,10,0.1)
158-
savejson('sparse',data2json)
176+
savejson('sparse',data2json,'FloatFormat','%.18g')
159177
json2data=loadjson(ans)
178+
if(~isequaln(json2data.sparse,data2json))
179+
warning('conversion does not preserve original data');
180+
end
160181

161182
fprintf(1,'\n%%=================================================\n')
162183
fprintf(1,'%% a complex sparse matrix\n')
163184
fprintf(1,'%%=================================================\n\n')
164185

186+
data2json=sprand(10,10,0.1);
165187
data2json=data2json-data2json*1i
166-
savejson('complex_sparse',data2json)
188+
savejson('complex_sparse',data2json,'FloatFormat','%.18g')
167189
json2data=loadjson(ans)
190+
if(~isequaln(json2data.complex_sparse,data2json))
191+
warning('conversion does not preserve original data');
192+
end
168193

169194
fprintf(1,'\n%%=================================================\n')
170195
fprintf(1,'%% an all-zero sparse matrix\n')
@@ -173,6 +198,9 @@
173198
data2json=sparse(2,3);
174199
savejson('all_zero_sparse',data2json)
175200
json2data=loadjson(ans)
201+
if(~isequaln(json2data.all_zero_sparse,data2json))
202+
warning('conversion does not preserve original data');
203+
end
176204

177205
fprintf(1,'\n%%=================================================\n')
178206
fprintf(1,'%% an empty sparse matrix\n')
@@ -181,6 +209,9 @@
181209
data2json=sparse([]);
182210
savejson('empty_sparse',data2json)
183211
json2data=loadjson(ans)
212+
if(~isequaln(json2data.empty_sparse,data2json))
213+
warning('conversion does not preserve original data');
214+
end
184215

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

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

0 commit comments

Comments
 (0)