@@ -370,8 +370,9 @@ _noop (void)
370
370
read_state_names[bson->read_state]); \
371
371
return; \
372
372
}
373
- #define HANDLE_OPTION (_key , _type , _state ) \
374
- (len == strlen (_key) && strncmp ((const char *) val, (_key), len) == 0) \
373
+ #define HANDLE_OPTION (_selection_statement , _key , _type , _state ) \
374
+ _selection_statement (len == strlen (_key) && \
375
+ strncmp ((const char *) val, (_key), len) == 0) \
375
376
{ \
376
377
if (bson->bson_type && bson->bson_type != (_type)) { \
377
378
_bson_json_read_set_error (reader, \
@@ -1368,98 +1369,98 @@ _bson_json_read_map_key (bson_json_reader_t *reader, /* IN */
1368
1369
_bson_json_save_map_key (bson , val , len );
1369
1370
}
1370
1371
1371
- /* clang-format off */
1372
1372
if (bson -> read_state == BSON_JSON_IN_BSON_TYPE ) {
1373
- if
1374
- HANDLE_OPTION ("$regex" , BSON_TYPE_REGEX , BSON_JSON_LF_REGEX )
1375
- else if
1376
- HANDLE_OPTION ("$options" , BSON_TYPE_REGEX , BSON_JSON_LF_OPTIONS )
1377
- else if
1378
- HANDLE_OPTION ("$oid" , BSON_TYPE_OID , BSON_JSON_LF_OID )
1379
- else if
1380
- HANDLE_OPTION ("$binary" , BSON_TYPE_BINARY , BSON_JSON_LF_BINARY )
1381
- else if
1382
- HANDLE_OPTION ("$type" , BSON_TYPE_BINARY , BSON_JSON_LF_TYPE )
1383
- else if
1384
- HANDLE_OPTION ("$uuid" , BSON_TYPE_BINARY , BSON_JSON_LF_UUID )
1385
- else if
1386
- HANDLE_OPTION ("$date" , BSON_TYPE_DATE_TIME , BSON_JSON_LF_DATE )
1387
- else if
1388
- HANDLE_OPTION (
1389
- "$undefined" , BSON_TYPE_UNDEFINED , BSON_JSON_LF_UNDEFINED )
1390
- else if
1391
- HANDLE_OPTION ("$minKey" , BSON_TYPE_MINKEY , BSON_JSON_LF_MINKEY )
1392
- else if
1393
- HANDLE_OPTION ("$maxKey" , BSON_TYPE_MAXKEY , BSON_JSON_LF_MAXKEY )
1394
- else if
1395
- HANDLE_OPTION ("$numberInt" , BSON_TYPE_INT32 , BSON_JSON_LF_INT32 )
1396
- else if
1397
- HANDLE_OPTION ("$numberLong" , BSON_TYPE_INT64 , BSON_JSON_LF_INT64 )
1398
- else if
1399
- HANDLE_OPTION ("$numberDouble" , BSON_TYPE_DOUBLE , BSON_JSON_LF_DOUBLE )
1400
- else if
1401
- HANDLE_OPTION ("$symbol" , BSON_TYPE_SYMBOL , BSON_JSON_LF_SYMBOL )
1402
- else if
1403
- HANDLE_OPTION (
1404
- "$numberDecimal" , BSON_TYPE_DECIMAL128 , BSON_JSON_LF_DECIMAL128 )
1405
- else if (!strcmp ("$timestamp" , (const char * ) val )) {
1373
+ HANDLE_OPTION (if , "$regex" , BSON_TYPE_REGEX , BSON_JSON_LF_REGEX )
1374
+ HANDLE_OPTION (else if , "$options" , BSON_TYPE_REGEX , BSON_JSON_LF_OPTIONS )
1375
+ HANDLE_OPTION (else if , "$oid" , BSON_TYPE_OID , BSON_JSON_LF_OID )
1376
+ HANDLE_OPTION (else if , "$binary" , BSON_TYPE_BINARY , BSON_JSON_LF_BINARY )
1377
+ HANDLE_OPTION (else if , "$type" , BSON_TYPE_BINARY , BSON_JSON_LF_TYPE )
1378
+ HANDLE_OPTION (else if , "$uuid" , BSON_TYPE_BINARY , BSON_JSON_LF_UUID )
1379
+ HANDLE_OPTION (else if , "$date" , BSON_TYPE_DATE_TIME , BSON_JSON_LF_DATE )
1380
+ HANDLE_OPTION (
1381
+ else if , "$undefined" , BSON_TYPE_UNDEFINED , BSON_JSON_LF_UNDEFINED )
1382
+ HANDLE_OPTION (else if , "$minKey" , BSON_TYPE_MINKEY , BSON_JSON_LF_MINKEY )
1383
+ HANDLE_OPTION (else if , "$maxKey" , BSON_TYPE_MAXKEY , BSON_JSON_LF_MAXKEY )
1384
+ HANDLE_OPTION (else if , "$numberInt" , BSON_TYPE_INT32 , BSON_JSON_LF_INT32 )
1385
+ HANDLE_OPTION (
1386
+ else if , "$numberLong" , BSON_TYPE_INT64 , BSON_JSON_LF_INT64 )
1387
+ HANDLE_OPTION (
1388
+ else if , "$numberDouble" , BSON_TYPE_DOUBLE , BSON_JSON_LF_DOUBLE )
1389
+ HANDLE_OPTION (else if , "$symbol" , BSON_TYPE_SYMBOL , BSON_JSON_LF_SYMBOL )
1390
+ HANDLE_OPTION (else if ,
1391
+ "$numberDecimal" ,
1392
+ BSON_TYPE_DECIMAL128 ,
1393
+ BSON_JSON_LF_DECIMAL128 )
1394
+ else if (!strcmp ("$timestamp" , (const char * ) val ))
1395
+ {
1406
1396
bson -> bson_type = BSON_TYPE_TIMESTAMP ;
1407
1397
bson -> read_state = BSON_JSON_IN_BSON_TYPE_TIMESTAMP_STARTMAP ;
1408
- } else if (!strcmp ("$regularExpression" , (const char * ) val )) {
1398
+ }
1399
+ else if (!strcmp ("$regularExpression" , (const char * ) val ))
1400
+ {
1409
1401
bson -> bson_type = BSON_TYPE_REGEX ;
1410
1402
bson -> read_state = BSON_JSON_IN_BSON_TYPE_REGEX_STARTMAP ;
1411
- } else if (!strcmp ("$dbPointer" , (const char * ) val )) {
1403
+ }
1404
+ else if (!strcmp ("$dbPointer" , (const char * ) val ))
1405
+ {
1412
1406
/* start parsing "key": {"$dbPointer": {...}}, save "key" for later */
1413
1407
_bson_json_buf_set (
1414
1408
& bson -> dbpointer_key , bson -> key_buf .buf , bson -> key_buf .len );
1415
1409
1416
1410
bson -> bson_type = BSON_TYPE_DBPOINTER ;
1417
1411
bson -> read_state = BSON_JSON_IN_BSON_TYPE_DBPOINTER_STARTMAP ;
1418
- } else if (!strcmp ("$code" , (const char * ) val )) {
1412
+ }
1413
+ else if (!strcmp ("$code" , (const char * ) val ))
1414
+ {
1419
1415
_bson_json_read_code_or_scope_key (
1420
1416
bson , false /* is_scope */ , val , len );
1421
- } else if (!strcmp ("$scope" , (const char * ) val )) {
1417
+ }
1418
+ else if (!strcmp ("$scope" , (const char * ) val ))
1419
+ {
1422
1420
_bson_json_read_code_or_scope_key (
1423
1421
bson , true /* is_scope */ , val , len );
1424
- } else {
1422
+ }
1423
+ else
1424
+ {
1425
1425
_bson_json_bad_key_in_type (reader , val );
1426
1426
}
1427
1427
} else if (bson -> read_state == BSON_JSON_IN_BSON_TYPE_DATE_NUMBERLONG ) {
1428
- if
1429
- HANDLE_OPTION ( "$numberLong" , BSON_TYPE_DATE_TIME , BSON_JSON_LF_INT64 )
1430
- else {
1428
+ HANDLE_OPTION ( if , "$numberLong" , BSON_TYPE_DATE_TIME , BSON_JSON_LF_INT64 )
1429
+ else
1430
+ {
1431
1431
_bson_json_bad_key_in_type (reader , val );
1432
1432
}
1433
1433
} else if (bson -> read_state == BSON_JSON_IN_BSON_TYPE_TIMESTAMP_VALUES ) {
1434
- if
1435
- HANDLE_OPTION ("t" , BSON_TYPE_TIMESTAMP , BSON_JSON_LF_TIMESTAMP_T )
1436
- else if
1437
- HANDLE_OPTION ( "i" , BSON_TYPE_TIMESTAMP , BSON_JSON_LF_TIMESTAMP_I )
1438
- else {
1434
+ HANDLE_OPTION ( if , "t" , BSON_TYPE_TIMESTAMP , BSON_JSON_LF_TIMESTAMP_T )
1435
+ HANDLE_OPTION (
1436
+ else if , "i" , BSON_TYPE_TIMESTAMP , BSON_JSON_LF_TIMESTAMP_I )
1437
+ else
1438
+ {
1439
1439
_bson_json_bad_key_in_type (reader , val );
1440
1440
}
1441
1441
} else if (bson -> read_state == BSON_JSON_IN_BSON_TYPE_REGEX_VALUES ) {
1442
- if
1443
- HANDLE_OPTION (
1444
- "pattern" , BSON_TYPE_REGEX , BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN )
1445
- else if
1446
- HANDLE_OPTION (
1447
- "options" , BSON_TYPE_REGEX , BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS )
1448
- else {
1442
+ HANDLE_OPTION (if ,
1443
+ "pattern" ,
1444
+ BSON_TYPE_REGEX ,
1445
+ BSON_JSON_LF_REGULAR_EXPRESSION_PATTERN )
1446
+ HANDLE_OPTION (else if ,
1447
+ "options" ,
1448
+ BSON_TYPE_REGEX ,
1449
+ BSON_JSON_LF_REGULAR_EXPRESSION_OPTIONS )
1450
+ else
1451
+ {
1449
1452
_bson_json_bad_key_in_type (reader , val );
1450
1453
}
1451
1454
} else if (bson -> read_state == BSON_JSON_IN_BSON_TYPE_BINARY_VALUES ) {
1452
- if
1453
- HANDLE_OPTION ("base64" , BSON_TYPE_BINARY , BSON_JSON_LF_BINARY )
1454
- else if
1455
- HANDLE_OPTION ("subType" , BSON_TYPE_BINARY , BSON_JSON_LF_TYPE )
1456
- else {
1455
+ HANDLE_OPTION (if , "base64" , BSON_TYPE_BINARY , BSON_JSON_LF_BINARY )
1456
+ HANDLE_OPTION (else if , "subType" , BSON_TYPE_BINARY , BSON_JSON_LF_TYPE )
1457
+ else
1458
+ {
1457
1459
_bson_json_bad_key_in_type (reader , val );
1458
1460
}
1459
1461
} else {
1460
1462
_bson_json_save_map_key (bson , val , len );
1461
1463
}
1462
- /* clang-format on */
1463
1464
}
1464
1465
1465
1466
0 commit comments