From c4325a38fb6ff243f6e77fba2a47c2bc77528eec Mon Sep 17 00:00:00 2001 From: CK Tan Date: Wed, 27 Feb 2019 11:31:49 -0800 Subject: [PATCH] add toml_array_type() api --- toml.c | 11 +++++++++++ toml.h | 7 +++++++ 2 files changed, 18 insertions(+) diff --git a/toml.c b/toml.c index 10f9db2..2aabe7c 100644 --- a/toml.c +++ b/toml.c @@ -1609,6 +1609,17 @@ char toml_array_kind(toml_array_t* arr) return arr->kind; } +char toml_array_type(toml_array_t* arr) +{ + if (arr->kind != 'v') + return 0; + + if (arr->nelem == 0) + return 0; + + return arr->type; +} + int toml_array_nelem(toml_array_t* arr) { diff --git a/toml.h b/toml.h index 67ab80d..0ec104a 100644 --- a/toml.h +++ b/toml.h @@ -68,6 +68,13 @@ TOML_EXTERN toml_table_t* toml_table_in(toml_table_t* tab, const char* key); /* Return the array kind: 't'able, 'a'rray, 'v'alue */ TOML_EXTERN char toml_array_kind(toml_array_t* arr); +/* For array kind 'v'alue, return the type of values + i:int, d:double, b:bool, s:string, t:time, D:date, T:timestamp + 0 if unknown +*/ +TOML_EXTERN char toml_array_type(toml_array_t* arr); + + /* Return the number of elements in the array */ TOML_EXTERN int toml_array_nelem(toml_array_t* arr);