From 88eacb3fe0807871cb7d7c8d61ca2043788c7fbc Mon Sep 17 00:00:00 2001 From: Stanley Pinchak Date: Tue, 8 Jan 2019 13:04:28 -0600 Subject: [PATCH 1/3] Add helper functions for tables New functions for read only access to internal nkval, narr and ntab members of toml_table_t structs. --- toml.c | 14 ++++++++++++++ toml.h | 9 +++++++++ 2 files changed, 23 insertions(+) diff --git a/toml.c b/toml.c index fbb1663..fde2122 100644 --- a/toml.c +++ b/toml.c @@ -1610,6 +1610,20 @@ char toml_array_kind(toml_array_t* arr) } +int toml_table_nkval(toml_table_t* tab) +{ + return tab->nkval; +} + +int toml_table_narr(toml_table_t* tab) +{ + return tab->narr; +} + +int toml_table_ntab(toml_table_t* tab) +{ + return tab->ntab; +} toml_array_t* toml_array_at(toml_array_t* arr, int idx) { diff --git a/toml.h b/toml.h index 54c1c82..58c3194 100644 --- a/toml.h +++ b/toml.h @@ -63,6 +63,15 @@ 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); +/* Return the number of key-values in a table */ +TOML_EXTERN int toml_table_nkval(toml_table_t* tab); + +/* Return the number of arrays in a table */ +TOML_EXTERN int toml_table_narr(toml_table_t* tab); + +/* Return the number of sub-tables in a table */ +TOML_EXTERN int toml_table_ntab(toml_table_t* tab); + /* Deref array by index. Return the element at idx or 0 if out of range. */ TOML_EXTERN const char* toml_raw_at(toml_array_t* arr, int idx); TOML_EXTERN toml_array_t* toml_array_at(toml_array_t* arr, int idx); From b53c016877c515357179e2b78e8cb86607852197 Mon Sep 17 00:00:00 2001 From: Stanley Pinchak Date: Tue, 8 Jan 2019 13:12:40 -0600 Subject: [PATCH 2/3] Add helper function for arrays New function for read only access to the internal nelem member of toml_array_t structs --- toml.c | 5 +++++ toml.h | 3 +++ 2 files changed, 8 insertions(+) diff --git a/toml.c b/toml.c index fde2122..24f4f69 100644 --- a/toml.c +++ b/toml.c @@ -1610,6 +1610,11 @@ char toml_array_kind(toml_array_t* arr) } +int toml_array_nelem(toml_array_t* arr) +{ + return arr->nelem; +} + int toml_table_nkval(toml_table_t* tab) { return tab->nkval; diff --git a/toml.h b/toml.h index 58c3194..9d33397 100644 --- a/toml.h +++ b/toml.h @@ -63,6 +63,9 @@ 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); +/* Return the number of elements in the array */ +TOML_EXTERN int toml_array_nelem(toml_array_t* arr); + /* Return the number of key-values in a table */ TOML_EXTERN int toml_table_nkval(toml_table_t* tab); From 3fed0ab4553ba6e66a192f7c4032c76770d5c283 Mon Sep 17 00:00:00 2001 From: Stanley Pinchak Date: Tue, 8 Jan 2019 13:15:59 -0600 Subject: [PATCH 3/3] Add helper functions to access key New functions for read only access to the key of toml_array_t and toml_table_t structs --- toml.c | 10 ++++++++++ toml.h | 6 ++++++ 2 files changed, 16 insertions(+) diff --git a/toml.c b/toml.c index 24f4f69..85d713d 100644 --- a/toml.c +++ b/toml.c @@ -1615,6 +1615,11 @@ int toml_array_nelem(toml_array_t* arr) return arr->nelem; } +const char* toml_array_key(toml_array_t* arr) +{ + return arr ? arr->key : (const char*) NULL; +} + int toml_table_nkval(toml_table_t* tab) { return tab->nkval; @@ -1630,6 +1635,11 @@ int toml_table_ntab(toml_table_t* tab) return tab->ntab; } +const char* toml_table_key(toml_table_t* tab) +{ + return tab ? tab->key : (const char*) NULL; +} + toml_array_t* toml_array_at(toml_array_t* arr, int idx) { if (arr->kind != 'a') diff --git a/toml.h b/toml.h index 9d33397..94469c7 100644 --- a/toml.h +++ b/toml.h @@ -66,6 +66,9 @@ TOML_EXTERN char toml_array_kind(toml_array_t* arr); /* Return the number of elements in the array */ TOML_EXTERN int toml_array_nelem(toml_array_t* arr); +/* Return the key of an array */ +TOML_EXTERN const char* toml_array_key(toml_array_t* arr); + /* Return the number of key-values in a table */ TOML_EXTERN int toml_table_nkval(toml_table_t* tab); @@ -75,6 +78,9 @@ TOML_EXTERN int toml_table_narr(toml_table_t* tab); /* Return the number of sub-tables in a table */ TOML_EXTERN int toml_table_ntab(toml_table_t* tab); +/* Return the key of a table*/ +TOML_EXTERN const char* toml_table_key(toml_table_t* tab); + /* Deref array by index. Return the element at idx or 0 if out of range. */ TOML_EXTERN const char* toml_raw_at(toml_array_t* arr, int idx); TOML_EXTERN toml_array_t* toml_array_at(toml_array_t* arr, int idx);