summaryrefslogtreecommitdiffstats
path: root/contrib/restricted/aws/aws-c-common/source/json.c
diff options
context:
space:
mode:
authorrobot-contrib <[email protected]>2022-10-28 07:50:04 +0300
committerrobot-contrib <[email protected]>2022-10-28 07:50:04 +0300
commit9b6cded108571fe7983a855c40c7545bf4b7aad2 (patch)
treebf5fe3a440a47d1a49f05eae25af134c0c831408 /contrib/restricted/aws/aws-c-common/source/json.c
parente86badd466683de764e9ca22bc185566b43b82e6 (diff)
Update contrib/restricted/aws/aws-c-common to 0.8.3
Diffstat (limited to 'contrib/restricted/aws/aws-c-common/source/json.c')
-rw-r--r--contrib/restricted/aws/aws-c-common/source/json.c84
1 files changed, 84 insertions, 0 deletions
diff --git a/contrib/restricted/aws/aws-c-common/source/json.c b/contrib/restricted/aws/aws-c-common/source/json.c
index 7f700af1fb3..77e7c1d6613 100644
--- a/contrib/restricted/aws/aws-c-common/source/json.c
+++ b/contrib/restricted/aws/aws-c-common/source/json.c
@@ -166,6 +166,37 @@ done:
return result;
}
+int aws_json_const_iterate_object(
+ const struct aws_json_value *object,
+ aws_json_on_member_encountered_const_fn *on_member,
+ void *user_data) {
+ int result = AWS_OP_ERR;
+
+ struct cJSON *cjson = (struct cJSON *)object;
+ if (!cJSON_IsObject(cjson)) {
+ aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ goto done;
+ }
+
+ const cJSON *key = NULL;
+ cJSON_ArrayForEach(key, cjson) {
+ bool should_continue = true;
+ struct aws_byte_cursor key_cur = aws_byte_cursor_from_c_str(key->string);
+ if (on_member(&key_cur, (struct aws_json_value *)key, &should_continue, user_data)) {
+ goto done;
+ }
+
+ if (!should_continue) {
+ break;
+ }
+ }
+
+ result = AWS_OP_SUCCESS;
+
+done:
+ return result;
+}
+
int aws_json_value_add_array_element(struct aws_json_value *array, const struct aws_json_value *value) {
struct cJSON *cjson = (struct cJSON *)array;
@@ -222,6 +253,59 @@ int aws_json_value_remove_array_element(struct aws_json_value *array, size_t ind
return AWS_OP_SUCCESS;
}
+int aws_json_const_iterate_array(
+ const struct aws_json_value *array,
+ aws_json_on_value_encountered_const_fn *on_value,
+ void *user_data) {
+ int result = AWS_OP_ERR;
+
+ struct cJSON *cjson = (struct cJSON *)array;
+ if (!cJSON_IsArray(cjson)) {
+ aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ goto done;
+ }
+
+ size_t idx = 0;
+ const cJSON *value = NULL;
+ cJSON_ArrayForEach(value, cjson) {
+ bool should_continue = true;
+ if (on_value(idx, (struct aws_json_value *)value, &should_continue, user_data)) {
+ goto done;
+ }
+
+ if (!should_continue) {
+ break;
+ }
+ ++idx;
+ }
+
+ result = AWS_OP_SUCCESS;
+
+done:
+ return result;
+}
+
+bool aws_json_value_compare(const struct aws_json_value *a, const struct aws_json_value *b, bool is_case_sensitive) {
+ struct cJSON *cjson_a = (struct cJSON *)a;
+ struct cJSON *cjson_b = (struct cJSON *)b;
+ return cJSON_Compare(cjson_a, cjson_b, is_case_sensitive);
+}
+
+struct aws_json_value *aws_json_value_duplicate(const struct aws_json_value *value) {
+ struct cJSON *cjson = (struct cJSON *)value;
+ if (cJSON_IsInvalid(cjson)) {
+ aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ return NULL;
+ }
+
+ struct cJSON *ret = cJSON_Duplicate(cjson, true);
+ if (ret == NULL) {
+ aws_raise_error(AWS_ERROR_INVALID_ARGUMENT);
+ }
+
+ return (void *)ret;
+}
+
bool aws_json_value_is_string(const struct aws_json_value *value) {
struct cJSON *cjson = (struct cJSON *)value;
if (cJSON_IsInvalid(cjson)) {