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