@@ -42,16 +42,16 @@ private _createObject = {
42
42
switch (_objectType ) do {
43
43
case false ;
44
44
case 0 : {
45
- [] call CBA_fnc_createNamespace ;
45
+ [] call CBA_fnc_createNamespace
46
46
};
47
47
48
48
case true ;
49
49
case 1 : {
50
- [] call CBA_fnc_hashCreate ;
50
+ [] call CBA_fnc_hashCreate
51
51
};
52
52
53
53
case 2 : {
54
- createHashMap ;
54
+ createHashMap
55
55
};
56
56
};
57
57
};
@@ -88,15 +88,15 @@ private _objectSet = {
88
88
private _tokenize = {
89
89
params [[" _jsonStr" , objNull , [" " ]]];
90
90
91
- if ( ! (_jsonStr isEqualType " " ) ) exitWith {
92
- objNull ;
91
+ if ! (_jsonStr isEqualType " " ) exitWith {
92
+ objNull
93
93
};
94
94
95
95
private _tokens = [];
96
96
97
97
private _symbolsArr = " {}[]:," splitString " " ;
98
98
private _numberArr = " -0123456789" splitString " " ;
99
- private _whitespaceArr = [0x9 , 0xA , 0xD , 0x20 ] apply { toString [ _x ] } ;
99
+ private _whitespaceChars = toString [0x9 , 0xA , 0xD , 0x20 ];
100
100
101
101
private _constRegex = " true|false|null/o" ;
102
102
private _numberRegex = " (-?(?:(?:[1-9]\d*)|\d)(?:\.\d+)?(?:[eE][+-]?\d+)?).*/o" ;
@@ -128,7 +128,7 @@ private _tokenize = {
128
128
private _rmatch = flatten (((_codePoints select [0 , 5 ]) joinString " " ) regexFind [_constRegex ]);
129
129
if (count _rmatch > 0 ) then {
130
130
// Ensure match starts at beginning
131
- if (( _rmatch # 1 ) == 0 ) then {
131
+ if (_rmatch # 1 == 0 ) then {
132
132
switch (_rmatch # 0 ) do {
133
133
case " true" : {
134
134
_tokens pushBack [true , [_rowIndex , _columnIndex ]];
@@ -158,7 +158,7 @@ private _tokenize = {
158
158
private _cp = _codePoints # 0 ;
159
159
160
160
// Match against whitespace
161
- if (_cp in _whitespaceArr ) then {
161
+ if (_cp in _whitespaceChars ) then {
162
162
// Omit whitespace from tokenized output
163
163
_codePoints deleteAt 0 ;
164
164
_columnIndex = _columnIndex + 1 ;
@@ -195,14 +195,14 @@ private _tokenize = {
195
195
};
196
196
197
197
private _rmatch = ((_numberSym + _ncps ) regexFind [_numberRegex , 0 ]);
198
- if (( count _rmatch ) == 0 ) then {
199
- throw ( format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ]) ;
198
+ if (count _rmatch == 0 ) then {
199
+ throw format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ];
200
200
};
201
201
202
202
_rmatch = _rmatch # 0 # 1 ;
203
203
if (_rmatch # 1 ! = 0 ) then {
204
204
// Regex match must be at the beginning to denote a valid number
205
- throw ( format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ]) ;
205
+ throw format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ];
206
206
};
207
207
208
208
private _nextNumberSym = _rmatch # 0 ;
@@ -219,7 +219,7 @@ private _tokenize = {
219
219
220
220
// Reject case where the match is a single minus sign
221
221
if (_numberSym == " -" ) then {
222
- throw ( format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ]) ;
222
+ throw format [" invalid number token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ];
223
223
};
224
224
225
225
_tokens pushBack [parseNumber _numberSym , [_rowIndex , _columnIndex ]];
@@ -240,14 +240,14 @@ private _tokenize = {
240
240
241
241
if (isNil " _ncp" ) then {
242
242
// End of input reached before string terminated
243
- throw ( format [" unterminated string token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ]) ;
243
+ throw format [" unterminated string token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ];
244
244
};
245
245
246
246
_strExtent = _strExtent + 1 ;
247
247
248
248
if (_currentlyEscaping ) then {
249
249
if (! (_ncp in _strEscapeMap ) && _ncp ! = " u" ) then {
250
- throw ( format [" invalid string escape char '%1' at %2:%3" , _ncp , _rowIndex + 1 , _columnIndex + _strExtent ]) ;
250
+ throw format [" invalid string escape char '%1' at %2:%3" , _ncp , _rowIndex + 1 , _columnIndex + _strExtent ];
251
251
};
252
252
253
253
if (_ncp in _strEscapeMap ) then {
@@ -256,9 +256,9 @@ private _tokenize = {
256
256
private _hexStr = _codePoints select [_strExtent , 4 ];
257
257
_strExtent = _strExtent + 4 ;
258
258
259
- if ( ! ((_hexStr joinString " " ) regexMatch _hexStrRegex ) ) then {
259
+ if ! ((_hexStr joinString " " ) regexMatch _hexStrRegex ) then {
260
260
// Invalid hex string
261
- throw ( format [" invalid hex string '%1' at %2:%3" , _hexStr , _rowIndex + 1 , _columnIndex + 1 ]) ;
261
+ throw format [" invalid hex string '%1' at %2:%3" , _hexStr , _rowIndex + 1 , _columnIndex + 1 ];
262
262
};
263
263
264
264
private _cp = 0 ;
@@ -285,7 +285,7 @@ private _tokenize = {
285
285
286
286
private _ncpValue = (toArray _ncp ) # 0 ;
287
287
if (_ncpValue < 0x20 || _ncpValue > 0x10FFFF ) then {
288
- throw ( format [" invalid string code point at %1:%2" , _rowIndex + 1 , _columnIndex + _strExtent ]) ;
288
+ throw format [" invalid string code point at %1:%2" , _rowIndex + 1 , _columnIndex + _strExtent ];
289
289
};
290
290
291
291
_strSym = _strSym + _ncp ;
@@ -297,11 +297,11 @@ private _tokenize = {
297
297
continue ;
298
298
};
299
299
300
- throw ( format [" unexpected token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ]) ;
300
+ throw format [" unexpected token at %1:%2" , _rowIndex + 1 , _columnIndex + 1 ];
301
301
};
302
302
303
303
// Return parsed tokens
304
- _tokens ;
304
+ _tokens
305
305
};
306
306
307
307
/* *
@@ -317,9 +317,9 @@ private _shift = {
317
317
if (count _tokens > 0 ) then {
318
318
// Append token reduction state on to end of each token
319
319
_parseStack pushBack ((_tokens deleteAt 0 ) + [false ]);
320
- true ;
320
+ true
321
321
} else {
322
- false ;
322
+ false
323
323
};
324
324
};
325
325
@@ -336,14 +336,14 @@ private _reduce = {
336
336
params [[" _parseStack" , [], [[]]], [" _reducerState" , createHashMap , [createHashMap ]]];
337
337
338
338
if (count _parseStack == 0 ) exitWith {
339
- false ;
339
+ false
340
340
};
341
341
342
342
// Initialize reducer state if not already initialized
343
- if ( ! (" STACK_{" in _reducerState ) ) then {
343
+ if ! (" STACK_{" in _reducerState ) then {
344
344
_reducerState set [" STACK_{" , []];
345
345
};
346
- if ( ! (" STACK_[" in _reducerState ) ) then {
346
+ if ! (" STACK_[" in _reducerState ) then {
347
347
_reducerState set [" STACK_[" , []];
348
348
};
349
349
@@ -354,19 +354,19 @@ private _reduce = {
354
354
355
355
// Handle terminal symbols
356
356
switch (true ) do {
357
- case (( _topToken # 0 ) isEqualType 0 ): {
357
+ case (_topToken # 0 isEqualType 0 ): {
358
358
_topToken set [2 , true ];
359
359
};
360
360
361
- case (( _topToken # 0 ) isEqualType true ): {
361
+ case (_topToken # 0 isEqualType true ): {
362
362
_topToken set [2 , true ];
363
363
};
364
364
365
- case (( _topToken # 0 ) isEqualTo objNull ): {
365
+ case (_topToken # 0 isEqualTo objNull ): {
366
366
_topToken set [2 , true ];
367
367
};
368
368
369
- case ((( _topToken # 0 ) select [0 , 1 ]) == " $" ): {
369
+ case ((_topToken # 0 select [0 , 1 ]) == " $" ): {
370
370
_topToken set [0 , (_topToken # 0 ) select [1 ]];
371
371
_topToken set [2 , true ];
372
372
};
@@ -386,7 +386,7 @@ private _reduce = {
386
386
387
387
case " }" : {
388
388
if (count _objOpenStack == 0 ) then {
389
- throw ( format ([" invalid '}' token at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }) ));
389
+ throw format ([" invalid '}' token at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }));
390
390
};
391
391
392
392
private _objStart = _objOpenStack deleteAt (count _objOpenStack - 1 );
@@ -402,26 +402,26 @@ private _reduce = {
402
402
{
403
403
switch (_nextTokenType ) do {
404
404
case 0 : {
405
- if ( ! (_x # 2 ) ) then {
406
- throw ( format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }) ));
405
+ if ! (_x # 2 ) then {
406
+ throw format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }));
407
407
};
408
408
409
- if ( ! (_x # 0 isEqualType " " ) ) then {
410
- throw ( format ([" invalid key token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }) ));
409
+ if ! (_x # 0 isEqualType " " ) then {
410
+ throw format ([" invalid key token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }));
411
411
};
412
412
413
413
_currentKey = _x # 0 ;
414
414
};
415
415
416
416
case 1 : {
417
417
if (_x # 2 || _x # 0 ! = " :" ) then {
418
- throw ( format ([" missing colon token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }) ));
418
+ throw format ([" missing colon token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }));
419
419
};
420
420
};
421
421
422
422
case 2 : {
423
- if ( ! (_x # 2 ) ) then {
424
- throw ( format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }) ));
423
+ if ! (_x # 2 ) then {
424
+ throw format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }));
425
425
};
426
426
427
427
[_obj , _currentKey , _x # 0 ] call _objectSet ;
@@ -430,7 +430,7 @@ private _reduce = {
430
430
431
431
case 3 : {
432
432
if (_x # 2 || _x # 0 ! = " ," ) then {
433
- throw ( format ([" missing comma token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }) ));
433
+ throw format ([" missing comma token at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }));
434
434
};
435
435
};
436
436
};
@@ -441,16 +441,16 @@ private _reduce = {
441
441
// Validate object definition state machine is in correct final state
442
442
if (_objEmpty ) then {
443
443
if (_nextTokenType ! = 0 ) then {
444
- throw ( format ([" incomplete object definition at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }) ));
444
+ throw format ([" incomplete object definition at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }));
445
445
};
446
446
} else {
447
447
if (_nextTokenType == 0 ) then {
448
448
private _commaToken = _parseStack select - 2 ;
449
- throw ( format ([" extraneous comma at %1:%2" ] + ((_commaToken # 1 ) apply { _x + 1 }) ));
449
+ throw format ([" extraneous comma at %1:%2" ] + ((_commaToken # 1 ) apply { _x + 1 }));
450
450
};
451
451
452
452
if (_nextTokenType ! = 3 ) then {
453
- throw ( format ([" incomplete object definition at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }) ));
453
+ throw format ([" incomplete object definition at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }));
454
454
}
455
455
};
456
456
@@ -463,7 +463,7 @@ private _reduce = {
463
463
464
464
case " ]" : {
465
465
if (count _arrOpenStack == 0 ) then {
466
- throw ( format ([" invalid ']' token at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }) ));
466
+ throw format ([" invalid ']' token at %1:%2" ] + ((_topToken # 1 ) apply { _x + 1 }));
467
467
};
468
468
469
469
private _arrStart = _arrOpenStack deleteAt (count _arrOpenStack - 1 );
@@ -474,15 +474,15 @@ private _reduce = {
474
474
475
475
{
476
476
if (_nextTokenItem ) then {
477
- if ( ! (_x # 2 ) ) then {
478
- throw ( format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }) ));
477
+ if ! (_x # 2 ) then {
478
+ throw format ([" invalid '%1' token at %2:%3" , _x # 0 ] + ((_x # 1 ) apply { _x + 1 }));
479
479
};
480
480
481
481
_arr pushBack (_x # 0 );
482
482
_nextTokenItem = false ;
483
483
} else {
484
484
if (_x # 2 || _x # 0 ! = " ," ) then {
485
- throw ( format ([" missing comma at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }) ));
485
+ throw format ([" missing comma at %1:%2" ] + ((_x # 1 ) apply { _x + 1 }));
486
486
};
487
487
488
488
_nextTokenItem = true ;
@@ -491,7 +491,7 @@ private _reduce = {
491
491
492
492
if (_nextTokenItem && count _arr > 0 ) then {
493
493
private _commaToken = _parseStack select - 2 ;
494
- throw ( format ([" extraneous comma at %1:%2" ] + ((_commaToken # 1 ) apply { _x + 1 }) ));
494
+ throw format ([" extraneous comma at %1:%2" ] + ((_commaToken # 1 ) apply { _x + 1 }));
495
495
};
496
496
497
497
private _arrToken = _parseStack # _arrStart ;
@@ -512,8 +512,8 @@ private _reduce = {
512
512
private _parse = {
513
513
params [[" _jsonStr" , objNull , [" " ]]];
514
514
515
- if ( ! (_jsonStr isEqualType " " ) ) exitWith {
516
- objNull ;
515
+ if ! (_jsonStr isEqualType " " ) exitWith {
516
+ objNull
517
517
};
518
518
519
519
private _tokens = [_jsonStr ] call _tokenize ;
@@ -526,7 +526,7 @@ private _parse = {
526
526
private _reducerState = createHashMap ;
527
527
528
528
while {true } do {
529
- if ( ! ([_parseStack , _tokens ] call _shift ) ) then {
529
+ if ! ([_parseStack , _tokens ] call _shift ) then {
530
530
break ;
531
531
};
532
532
@@ -535,16 +535,16 @@ private _parse = {
535
535
536
536
if (count _parseStack > 1 ) then {
537
537
private _extraneousToken = _parseStack # 1 ;
538
- throw ( format ([" extraneous '%1' token at %2:%3" , _extraneousToken # 0 ] + ((_extraneousToken # 1 ) apply { _x + 1 }) ));
538
+ throw format ([" extraneous '%1' token at %2:%3" , _extraneousToken # 0 ] + ((_extraneousToken # 1 ) apply { _x + 1 }));
539
539
};
540
540
541
541
// Extract and return parsed object
542
- _parseStack # 0 # 0 ;
542
+ _parseStack # 0 # 0
543
543
};
544
544
545
545
private _jsonValue = [_json ] call _parse ;
546
546
547
547
// Reset unicode processing
548
548
forceUnicode - 1 ;
549
549
550
- _jsonValue ;
550
+ _jsonValue
0 commit comments