Add helper functions to access key
New functions for read only access to the key of toml_array_t and toml_table_t structs
This commit is contained in:
parent
b53c016877
commit
3fed0ab455
2 changed files with 16 additions and 0 deletions
10
toml.c
10
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')
|
||||
|
|
6
toml.h
6
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);
|
||||
|
|
Loading…
Reference in a new issue