19750e409Sopenharmony_ci/* 29750e409Sopenharmony_ci Copyright (c) 2009-2017 Dave Gamble and cJSON contributors 39750e409Sopenharmony_ci 49750e409Sopenharmony_ci Permission is hereby granted, free of charge, to any person obtaining a copy 59750e409Sopenharmony_ci of this software and associated documentation files (the "Software"), to deal 69750e409Sopenharmony_ci in the Software without restriction, including without limitation the rights 79750e409Sopenharmony_ci to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 89750e409Sopenharmony_ci copies of the Software, and to permit persons to whom the Software is 99750e409Sopenharmony_ci furnished to do so, subject to the following conditions: 109750e409Sopenharmony_ci 119750e409Sopenharmony_ci The above copyright notice and this permission notice shall be included in 129750e409Sopenharmony_ci all copies or substantial portions of the Software. 139750e409Sopenharmony_ci 149750e409Sopenharmony_ci THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 159750e409Sopenharmony_ci IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 169750e409Sopenharmony_ci FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 179750e409Sopenharmony_ci AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 189750e409Sopenharmony_ci LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 199750e409Sopenharmony_ci OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 209750e409Sopenharmony_ci THE SOFTWARE. 219750e409Sopenharmony_ci*/ 229750e409Sopenharmony_ci 239750e409Sopenharmony_ci#ifndef cJSON_Utils__h 249750e409Sopenharmony_ci#define cJSON_Utils__h 259750e409Sopenharmony_ci 269750e409Sopenharmony_ci#ifdef __cplusplus 279750e409Sopenharmony_ciextern "C" 289750e409Sopenharmony_ci{ 299750e409Sopenharmony_ci#endif 309750e409Sopenharmony_ci 319750e409Sopenharmony_ci#include "cJSON.h" 329750e409Sopenharmony_ci 339750e409Sopenharmony_ci/* Implement RFC6901 (https://tools.ietf.org/html/rfc6901) JSON Pointer spec. */ 349750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GetPointer(cJSON * const object, const char *pointer); 359750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GetPointerCaseSensitive(cJSON * const object, const char *pointer); 369750e409Sopenharmony_ci 379750e409Sopenharmony_ci/* Implement RFC6902 (https://tools.ietf.org/html/rfc6902) JSON Patch spec. */ 389750e409Sopenharmony_ci/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */ 399750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatches(cJSON * const from, cJSON * const to); 409750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GeneratePatchesCaseSensitive(cJSON * const from, cJSON * const to); 419750e409Sopenharmony_ci/* Utility for generating patch array entries. */ 429750e409Sopenharmony_ciCJSON_PUBLIC(void) cJSONUtils_AddPatchToArray(cJSON * const array, const char * const operation, const char * const path, const cJSON * const value); 439750e409Sopenharmony_ci/* Returns 0 for success. */ 449750e409Sopenharmony_ciCJSON_PUBLIC(int) cJSONUtils_ApplyPatches(cJSON * const object, const cJSON * const patches); 459750e409Sopenharmony_ciCJSON_PUBLIC(int) cJSONUtils_ApplyPatchesCaseSensitive(cJSON * const object, const cJSON * const patches); 469750e409Sopenharmony_ci 479750e409Sopenharmony_ci/* 489750e409Sopenharmony_ci// Note that ApplyPatches is NOT atomic on failure. To implement an atomic ApplyPatches, use: 499750e409Sopenharmony_ci//int cJSONUtils_AtomicApplyPatches(cJSON **object, cJSON *patches) 509750e409Sopenharmony_ci//{ 519750e409Sopenharmony_ci// cJSON *modme = cJSON_Duplicate(*object, 1); 529750e409Sopenharmony_ci// int error = cJSONUtils_ApplyPatches(modme, patches); 539750e409Sopenharmony_ci// if (!error) 549750e409Sopenharmony_ci// { 559750e409Sopenharmony_ci// cJSON_Delete(*object); 569750e409Sopenharmony_ci// *object = modme; 579750e409Sopenharmony_ci// } 589750e409Sopenharmony_ci// else 599750e409Sopenharmony_ci// { 609750e409Sopenharmony_ci// cJSON_Delete(modme); 619750e409Sopenharmony_ci// } 629750e409Sopenharmony_ci// 639750e409Sopenharmony_ci// return error; 649750e409Sopenharmony_ci//} 659750e409Sopenharmony_ci// Code not added to library since this strategy is a LOT slower. 669750e409Sopenharmony_ci*/ 679750e409Sopenharmony_ci 689750e409Sopenharmony_ci/* Implement RFC7386 (https://tools.ietf.org/html/rfc7396) JSON Merge Patch spec. */ 699750e409Sopenharmony_ci/* target will be modified by patch. return value is new ptr for target. */ 709750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_MergePatch(cJSON *target, const cJSON * const patch); 719750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_MergePatchCaseSensitive(cJSON *target, const cJSON * const patch); 729750e409Sopenharmony_ci/* generates a patch to move from -> to */ 739750e409Sopenharmony_ci/* NOTE: This modifies objects in 'from' and 'to' by sorting the elements by their key */ 749750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatch(cJSON * const from, cJSON * const to); 759750e409Sopenharmony_ciCJSON_PUBLIC(cJSON *) cJSONUtils_GenerateMergePatchCaseSensitive(cJSON * const from, cJSON * const to); 769750e409Sopenharmony_ci 779750e409Sopenharmony_ci/* Given a root object and a target object, construct a pointer from one to the other. */ 789750e409Sopenharmony_ciCJSON_PUBLIC(char *) cJSONUtils_FindPointerFromObjectTo(const cJSON * const object, const cJSON * const target); 799750e409Sopenharmony_ci 809750e409Sopenharmony_ci/* Sorts the members of the object into alphabetical order. */ 819750e409Sopenharmony_ciCJSON_PUBLIC(void) cJSONUtils_SortObject(cJSON * const object); 829750e409Sopenharmony_ciCJSON_PUBLIC(void) cJSONUtils_SortObjectCaseSensitive(cJSON * const object); 839750e409Sopenharmony_ci 849750e409Sopenharmony_ci#ifdef __cplusplus 859750e409Sopenharmony_ci} 869750e409Sopenharmony_ci#endif 879750e409Sopenharmony_ci 889750e409Sopenharmony_ci#endif 89