| 1282 cx_attr_returns_nonnull |
1282 cx_attr_returns_nonnull |
| 1283 cx_attr_export |
1283 cx_attr_export |
| 1284 CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index); |
1284 CxJsonValue *cxJsonArrGet(const CxJsonValue *value, size_t index); |
| 1285 |
1285 |
| 1286 /** |
1286 /** |
| |
1287 * Removes an element from a JSON array. |
| |
1288 * |
| |
1289 * If the @p value is not a JSON array, the behavior is undefined. |
| |
1290 * |
| |
1291 * This function, in contrast to cxJsonArrayGet(), returns @c NULL |
| |
1292 * when the index is out of bounds. |
| |
1293 * |
| |
1294 * @param value the JSON value |
| |
1295 * @param index the index in the array |
| |
1296 * @return the removed value from the specified index or @c NULL when the index was out of bounds |
| |
1297 * @see cxJsonIsArray() |
| |
1298 */ |
| |
1299 cx_attr_nonnull |
| |
1300 cx_attr_export |
| |
1301 CxJsonValue *cxJsonArrRemove(CxJsonValue *value, size_t index); |
| |
1302 |
| |
1303 /** |
| 1287 * Returns an iterator over the JSON array elements. |
1304 * Returns an iterator over the JSON array elements. |
| 1288 * |
1305 * |
| 1289 * The iterator yields values of type @c CxJsonValue* . |
1306 * The iterator yields values of type @c CxJsonValue* . |
| 1290 * |
1307 * |
| 1291 * If the @p value is not a JSON array, the behavior is undefined. |
1308 * If the @p value is not a JSON array, the behavior is undefined. |
| 1322 cx_attr_nonnull |
1339 cx_attr_nonnull |
| 1323 cx_attr_returns_nonnull |
1340 cx_attr_returns_nonnull |
| 1324 cx_attr_export |
1341 cx_attr_export |
| 1325 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); |
1342 CxJsonValue *cx_json_obj_get_cxstr(const CxJsonValue *value, cxstring name); |
| 1326 |
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 |
| 1327 #ifdef __cplusplus |
1351 #ifdef __cplusplus |
| 1328 } // extern "C" |
1352 } // extern "C" |
| 1329 |
1353 |
| 1330 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { |
1354 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, cxstring name) { |
| 1331 return cx_json_obj_get_cxstr(value, name); |
1355 return cx_json_obj_get_cxstr(value, name); |
| 1335 return cx_json_obj_get_cxstr(value, cx_strcast(name)); |
1359 return cx_json_obj_get_cxstr(value, cx_strcast(name)); |
| 1336 } |
1360 } |
| 1337 |
1361 |
| 1338 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { |
1362 static inline CxJsonValue *cxJsonObjGet(const CxJsonValue *value, const char *name) { |
| 1339 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)); |
| 1340 } |
1376 } |
| 1341 |
1377 |
| 1342 extern "C" { |
1378 extern "C" { |
| 1343 #else |
1379 #else |
| 1344 /** |
1380 /** |
| 1378 cx_attr_returns_nonnull |
1414 cx_attr_returns_nonnull |
| 1379 cx_attr_cstr_arg(2) |
1415 cx_attr_cstr_arg(2) |
| 1380 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) { |
| 1381 return cx_json_obj_get_cxstr(value, cx_str(name)); |
1417 return cx_json_obj_get_cxstr(value, cx_str(name)); |
| 1382 } |
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 } |
| 1383 #endif |
1456 #endif |
| 1384 |
1457 |
| 1385 #ifdef __cplusplus |
1458 #ifdef __cplusplus |
| 1386 } |
1459 } |
| 1387 #endif |
1460 #endif |