You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by mi...@apache.org on 2018/08/30 12:35:05 UTC
svn commit: r1839675 - in /apr/apr/trunk: include/apr_json.h json/apr_json.c
Author: minfrin
Date: Thu Aug 30 12:35:05 2018
New Revision: 1839675
URL: http://svn.apache.org/viewvc?rev=1839675&view=rev
Log:
Add apr_json_object_first() and apr_json_object_next(), allowing the
caller to iterate through object key value pairs.
Modified:
apr/apr/trunk/include/apr_json.h
apr/apr/trunk/json/apr_json.c
Modified: apr/apr/trunk/include/apr_json.h
URL: http://svn.apache.org/viewvc/apr/apr/trunk/include/apr_json.h?rev=1839675&r1=1839674&r2=1839675&view=diff
==============================================================================
--- apr/apr/trunk/include/apr_json.h (original)
+++ apr/apr/trunk/include/apr_json.h Thu Aug 30 12:35:05 2018
@@ -278,6 +278,31 @@ APR_DECLARE(apr_json_kv_t *)
__attribute__((nonnull(1, 2)));
/**
+ * Get the first value associated with an object.
+ *
+ * If the value is an object, this function returns the first key value pair.
+ * @param obj The JSON object.
+ * @return Returns the first value, or NULL if not an object, or the object is
+ * empty.
+ */
+APR_DECLARE(apr_json_kv_t *) apr_json_object_first(apr_json_value_t *obj)
+ __attribute__((nonnull(1)));;
+
+/**
+ * Get the next value associated with an object.
+ *
+ * This function returns the next key value pair, or NULL if no more pairs
+ * are present.
+ * @param obj The JSON object.
+ * @param kv The previous JSON key value pair.
+ * @return Returns the next key value pair, or NULL if not an object, or
+ * the object is empty.
+ */
+APR_DECLARE(apr_json_kv_t *) apr_json_object_next(apr_json_value_t *obj,
+ apr_json_kv_t *kv)
+ __attribute__((nonnull(1, 2)));;
+
+/**
* Decode utf8-encoded JSON string into apr_json_value_t.
* @param retval the result
* @param injson utf8-encoded JSON string.
Modified: apr/apr/trunk/json/apr_json.c
URL: http://svn.apache.org/viewvc/apr/apr/trunk/json/apr_json.c?rev=1839675&r1=1839674&r2=1839675&view=diff
==============================================================================
--- apr/apr/trunk/json/apr_json.c (original)
+++ apr/apr/trunk/json/apr_json.c Thu Aug 30 12:35:05 2018
@@ -169,6 +169,42 @@ apr_json_kv_t *apr_json_object_get(apr_j
return apr_hash_get(object->value.object->hash, key, klen);
}
+apr_json_kv_t *apr_json_object_first(apr_json_value_t *obj)
+{
+ apr_json_kv_t *kv;
+
+ if (obj->type != APR_JSON_OBJECT) {
+ return NULL;
+ }
+
+ kv = APR_RING_FIRST(&(obj->value.object)->list);
+
+ if (kv != APR_RING_SENTINEL(&(obj->value.object)->list, apr_json_kv_t, link)) {
+ return kv;
+ }
+ else {
+ return NULL;
+ }
+}
+
+apr_json_kv_t *apr_json_object_next(apr_json_value_t *obj, apr_json_kv_t *kv)
+{
+ apr_json_kv_t *next;
+
+ if (obj->type != APR_JSON_OBJECT) {
+ return NULL;
+ }
+
+ next = APR_RING_NEXT((kv), link);
+
+ if (next != APR_RING_SENTINEL(&(obj->value.object)->list, apr_json_kv_t, link)) {
+ return next;
+ }
+ else {
+ return NULL;
+ }
+}
+
apr_json_value_t *apr_json_overlay(apr_pool_t *p,
apr_json_value_t *overlay, apr_json_value_t *base,
int flags)