src/cx/json.h

changeset 1338
cc153bffea28
parent 1337
6dfa1eb58ce3
equal deleted inserted replaced
1337:6dfa1eb58ce3 1338:cc153bffea28
1339 cx_attr_nonnull 1339 cx_attr_nonnull
1340 cx_attr_returns_nonnull 1340 cx_attr_returns_nonnull
1341 cx_attr_export 1341 cx_attr_export
1342 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); 1342 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name);
1343 1343
1344 /**
1345 * @copydoc cxJsonObjRemove()
1346 */
1347 cx_attr_nonnull
1348 cx_attr_export
1349 CxJsonValue *cx_json_obj_remove_cxstr(CxJsonValue *value, cxstring name);
1350
1344 #ifdef __cplusplus 1351 #ifdef __cplusplus
1345 } // extern "C" 1352 } // extern "C"
1346 1353
1347 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { 1354 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) {
1348 return cx_json_obj_get_cxstr(value, name); 1355 return cx_json_obj_get_cxstr(value, name);
1352 return cx_json_obj_get_cxstr(value, cx_strcast(name)); 1359 return cx_json_obj_get_cxstr(value, cx_strcast(name));
1353 } 1360 }
1354 1361
1355 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { 1362 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) {
1356 return cx_json_obj_get_cxstr(value, cx_str(name)); 1363 return cx_json_obj_get_cxstr(value, cx_str(name));
1364 }
1365
1366 static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, cxstring name) {
1367 return cx_json_obj_remove_cxstr(value, name);
1368 }
1369
1370 static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, cxmutstr name) {
1371 return cx_json_obj_remove_cxstr(value, cx_strcast(name));
1372 }
1373
1374 static inline CxJsonValue *cxJsonObjRemove(CxJsonValue *value, const char *name) {
1375 return cx_json_obj_remove_cxstr(value, cx_str(name));
1357 } 1376 }
1358 1377
1359 extern "C" { 1378 extern "C" {
1360 #else 1379 #else
1361 /** 1380 /**
1395 cx_attr_returns_nonnull 1414 cx_attr_returns_nonnull
1396 cx_attr_cstr_arg(2) 1415 cx_attr_cstr_arg(2)
1397 static inline CxJsonValue *cx_json_obj_get_str(const CxJsonValue *value, const char *name) { 1416 static inline CxJsonValue *cx_json_obj_get_str(const CxJsonValue *value, const char *name) {
1398 return cx_json_obj_get_cxstr(value, cx_str(name)); 1417 return cx_json_obj_get_cxstr(value, cx_str(name));
1399 } 1418 }
1419
1420 /**
1421 * Removes and returns a value corresponding to a key in a JSON object.
1422 *
1423 * If the @p value is not a JSON object, the behavior is undefined.
1424 *
1425 * This function, in contrast to cxJsonObjGet() returns @c NULL when the
1426 * object does not contain @p name.
1427 *
1428 * @param value the JSON object
1429 * @param name the key to look up
1430 * @return the value corresponding to the key or @c NULL when the key is not part of the object
1431 * @see cxJsonIsObject()
1432 */
1433 #define cxJsonObjRemove(value, name) _Generic((name), \
1434 cxstring: cx_json_obj_remove_cxstr, \
1435 cxmutstr: cx_json_obj_remove_mutstr, \
1436 char*: cx_json_obj_remove_str, \
1437 const char*: cx_json_obj_remove_str) \
1438 (value, name)
1439
1440 /**
1441 * @copydoc cxJsonObjRemove()
1442 */
1443 cx_attr_nonnull
1444 static inline CxJsonValue *cx_json_obj_remove_mutstr(CxJsonValue *value, cxmutstr name) {
1445 return cx_json_obj_remove_cxstr(value, cx_strcast(name));
1446 }
1447
1448 /**
1449 * @copydoc cxJsonObjRemove()
1450 */
1451 cx_attr_nonnull
1452 cx_attr_cstr_arg(2)
1453 static inline CxJsonValue *cx_json_obj_remove_str(CxJsonValue *value, const char *name) {
1454 return cx_json_obj_remove_cxstr(value, cx_str(name));
1455 }
1400 #endif 1456 #endif
1401 1457
1402 #ifdef __cplusplus 1458 #ifdef __cplusplus
1403 } 1459 }
1404 #endif 1460 #endif

mercurial