Merge pull request #12 from gotnone/helperfuncs

Helperfuncs
This commit is contained in:
CK Tan 2019-01-09 12:48:25 -08:00 committed by GitHub
commit 3b6fe37d66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 0 deletions

29
toml.c
View File

@ -1610,6 +1610,35 @@ char toml_array_kind(toml_array_t* arr)
}
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;
}
int toml_table_narr(toml_table_t* tab)
{
return tab->narr;
}
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)
{

18
toml.h
View File

@ -63,6 +63,24 @@ 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 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);
/* 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);
/* 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);