ソースを参照

cJSON_Version: returns a version string

This is useful to programmatically find out the version of cJSON that
has been used (useful in case of scripting language bindings for
example).
Max Bruckner 8 年 前
コミット
c49ffbfba8
3 ファイル変更15 行追加0 行削除
  1. 8 0
      cJSON.c
  2. 4 0
      cJSON.h
  3. 3 0
      test.c

+ 8 - 0
cJSON.c

@@ -58,6 +58,14 @@ const char *cJSON_GetErrorPtr(void)
     return global_ep;
 }
 
+extern const char* cJSON_Version(void)
+{
+    static char version[15];
+    sprintf(version, "%i.%i.%i", CJSON_VERSION_MAJOR, CJSON_VERSION_MINOR, CJSON_VERSION_PATCH);
+
+    return version;
+}
+
 /* case insensitive strcmp */
 static int cJSON_strcasecmp(const char *s1, const char *s2)
 {

+ 4 - 0
cJSON.h

@@ -32,6 +32,10 @@ extern "C"
 #define CJSON_VERSION_MAJOR 1
 #define CJSON_VERSION_MINOR 2
 #define CJSON_VERSION_PATCH 0
+
+/* returns the version of cJSON as a string */
+extern const char* cJSON_Version(void);
+
 #include <stddef.h>
 
 /* cJSON Types: */

+ 3 - 0
test.c

@@ -382,6 +382,9 @@ int main(void)
         "</body>\n"
         "</html>\n";
 
+    /* print the version */
+    printf("Version: %s\n", cJSON_Version());
+
     /* Process each json textblock by parsing, then rebuilding: */
     doit(text1);
     doit(text2);