aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
authorAntony Kellermann2018-07-06 08:54:12 -0400
committerAntony Kellermann2018-07-06 08:54:12 -0400
commitfc5600ffcdabeae01cbdfc3fae6cf7f348a88d3e (patch)
tree3525797f1530dcf16b5945c7fc00bee58ae6281d
parent832c3a4b2890ba3a589d88ec942709500f9c1a33 (diff)
downloadaur-fc5600ffcdabeae01cbdfc3fae6cf7f348a88d3e.tar.gz
Added is_string_json_array func
-rw-r--r--string-tick.c7
-rw-r--r--string-tick.h8
2 files changed, 15 insertions, 0 deletions
diff --git a/string-tick.c b/string-tick.c
index 66a54a1a9ec3..b916657c2ef6 100644
--- a/string-tick.c
+++ b/string-tick.c
@@ -93,4 +93,11 @@ void string_destroy(String** phString) {
void pointer_alloc_check(void* alloced) {
if (alloced == NULL)
EXIT_MSG("alloc failed!")
+}
+
+int is_string_json_array(const String* pString) {
+ Json* jobj = json_tokener_parse(pString->data);
+ int formatted = jobj != NULL && json_object_is_type(jobj, json_type_array);
+ json_object_put(jobj);
+ return formatted;
} \ No newline at end of file
diff --git a/string-tick.h b/string-tick.h
index 9ec763819b34..c360eba124a1 100644
--- a/string-tick.h
+++ b/string-tick.h
@@ -35,6 +35,7 @@
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
+#include <json-c/json_tokener.h>
#include <sys/stat.h>
typedef struct string {
@@ -103,4 +104,11 @@ void string_destroy(String** phString);
*/
void pointer_alloc_check(void* alloced);
+/**
+ * Returns 1 if the given String is JSON formatted.
+ * @param pString the String to check
+ * @return 1 if JSON formatted, 0 otherwise
+ */
+int is_string_json_array(const String* pString);
+
#endif \ No newline at end of file