2
0

cJSON_Utils.h 3.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /*
  2. Copyright (c) 2009-2017 Dave Gamble and cJSON contributors
  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:
  9. The above copyright notice and this permission notice shall be included in
  10. all copies or substantial portions of the Software.
  11. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  12. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  13. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  14. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  15. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  16. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  17. THE SOFTWARE.
  18. */
  19. #ifndef cJSON_Utils__h
  20. #define cJSON_Utils__h
  21. #ifdef __cplusplus
  22. extern "C"
  23. {
  24. #endif
  25. #include "cJSON.h"
  26. /* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */
  27. CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer);
  28. CJSON_PUBLIC(cJSON *) cJSONUtils_GetPointerCaseSensitive(cJSON * const object, const char *pointer);
  29. /* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */
  30. /* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
  31. CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to);
  32. CJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to);
  33. /* Utility for generating patch array entries. */
  34. CJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value);
  35. /* Returns 0 for success. */
  36. CJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches);
  37. CJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches);
  38. /*
  39. // Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use:
  40. //int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches)
  41. //{
  42. // cJSON *modme = cJSON_Duplicate(*object, 1);
  43. // int error = cJSONUtils_ApplyPatches(modme, patches);
  44. // if (!error)
  45. // {
  46. // cJSON_Delete(*object);
  47. // *object = modme;
  48. // }
  49. // else
  50. // {
  51. // cJSON_Delete(modme);
  52. // }
  53. //
  54. // return error;
  55. //}
  56. // Code not added to library since this strategy is a LOT slower.
  57. */
  58. /* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */
  59. /* target will be modified by patch. return value is new ptr for target. */
  60. CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch);
  61. CJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch);
  62. /* generates a patch to move from -> to */
  63. /* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */
  64. CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON * const from, cJSON * const to);
  65. CJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatchCaseSensitive(cJSON * const from, cJSON * const to);
  66. /* Given a root object and a target object, construct a pointer from one to the other. */
  67. CJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const object, const cJSON * const target);
  68. /* Sorts the members of the object into alphabetical order. */
  69. CJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON * const object);
  70. CJSON_PUBLIC(void) cJSONUtils_SortObjectCaseSensitive(cJSON * const object);
  71. #ifdef __cplusplus
  72. }
  73. #endif
  74. #endif