@@ -428,7 +428,6 @@ bool JSONVar::hasOwnProperty(const char* key) const
428
428
}
429
429
430
430
cJSON* json = cJSON_GetObjectItemCaseSensitive (_json, key);
431
-
432
431
return (json != NULL );
433
432
}
434
433
@@ -506,4 +505,85 @@ void JSONVar::replaceJson(struct cJSON* json)
506
505
}
507
506
}
508
507
508
+ // ---------------------------------------------------------------------
509
+
510
+ bool JSONVar::hasPropertyEqual (const char * key, const char * value) const {
511
+ if (!cJSON_IsObject (_json)) {
512
+ return false ;
513
+ }
514
+
515
+ cJSON* json = cJSON_GetObjectItemCaseSensitive (_json, key);
516
+ return json != NULL && strcmp (value, json->valuestring ) == 0 ;
517
+ }
518
+
519
+ // ---------------------------------------------------------------------
520
+
521
+ bool JSONVar::hasPropertyEqual (const char * key, const JSONVar& value) const {
522
+ return this ->hasPropertyEqual (key, (const char *)value);
523
+ }
524
+
525
+ // ---------------------------------------------------------------------
526
+
527
+ bool JSONVar::hasPropertyEqual (const String& key, const String& value) const {
528
+ return this ->hasPropertyEqual (key.c_str (), value.c_str ());
529
+ }
530
+
531
+ // ---------------------------------------------------------------------
532
+
533
+ bool JSONVar::hasPropertyEqual (const String& key, const JSONVar& value) const {
534
+ return this ->hasPropertyEqual (key.c_str (), (const char *)value);
535
+ }
536
+
537
+ // ---------------------------------------------------------------------
538
+
539
+ JSONVar JSONVar::filter (const char * key, const char * value) const {
540
+ cJSON* item;
541
+ cJSON* test;
542
+ cJSON* json = cJSON_CreateArray ();
543
+
544
+ if (cJSON_IsObject (_json)){
545
+ test = cJSON_GetObjectItem (_json, key);
546
+
547
+ if (test != NULL && strcmp (value, test->valuestring ) == 0 ){
548
+ return (*this );
549
+ }
550
+ }
551
+
552
+ for (int i = 0 ; i < cJSON_GetArraySize (_json); i++) {
553
+ item = cJSON_GetArrayItem (_json, i);
554
+
555
+ if (item == NULL ) {
556
+ continue ;
557
+ }
558
+
559
+ test = cJSON_GetObjectItem (item, key);
560
+
561
+ if (test != NULL && strcmp (value, test->valuestring ) == 0 ){
562
+ cJSON_AddItemToArray (json, cJSON_Duplicate (item,true ));
563
+ }
564
+ }
565
+
566
+ if (cJSON_GetArraySize (json) == 0 ){
567
+ return JSONVar (NULL , NULL );
568
+ }
569
+
570
+ if (cJSON_GetArraySize (json) == 1 ){
571
+ return JSONVar (cJSON_GetArrayItem (json, 0 ), _json);
572
+ }
573
+
574
+ return JSONVar (json, _json);
575
+ }
576
+
577
+ JSONVar JSONVar::filter (const char * key, const JSONVar& value) const {
578
+ return this ->filter (key, (const char *)value);
579
+ }
580
+
581
+ JSONVar JSONVar::filter (const String& key, const String& value) const {
582
+ return this ->filter (key.c_str (), value.c_str ());
583
+ }
584
+
585
+ JSONVar JSONVar::filter (const String& key, const JSONVar& value) const {
586
+ return this ->filter (key.c_str (), (const char *)value);
587
+ }
588
+
509
589
JSONVar undefined;
0 commit comments