add toml_key_exists()
This commit is contained in:
parent
208203af46
commit
37954d9b20
3 changed files with 24 additions and 3 deletions
2
LICENSE
2
LICENSE
|
@ -1,6 +1,6 @@
|
|||
MIT License
|
||||
|
||||
Copyright (c) 2017 CK Tan
|
||||
Copyright (c) CK Tan
|
||||
https://github.com/cktan/tomlc99
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
|
21
toml.c
21
toml.c
|
@ -2,7 +2,7 @@
|
|||
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 - 2021 CK Tan
|
||||
Copyright (c) CK Tan
|
||||
https://github.com/cktan/tomlc99
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -1806,6 +1806,25 @@ const char* toml_key_in(const toml_table_t* tab, int keyidx)
|
|||
return 0;
|
||||
}
|
||||
|
||||
int toml_key_exists(const toml_table_t* tab, const char* key)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < tab->nkval; i++) {
|
||||
if (0 == strcmp(key, tab->kval[i]->key))
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < tab->narr; i++) {
|
||||
if (0 == strcmp(key, tab->arr[i]->key))
|
||||
return 1;
|
||||
}
|
||||
for (i = 0; i < tab->ntab; i++) {
|
||||
if (0 == strcmp(key, tab->tab[i]->key))
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
toml_raw_t toml_raw_in(const toml_table_t* tab, const char* key)
|
||||
{
|
||||
int i;
|
||||
|
|
4
toml.h
4
toml.h
|
@ -1,7 +1,7 @@
|
|||
/*
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2017 - 2019 CK Tan
|
||||
Copyright (c) CK Tan
|
||||
https://github.com/cktan/tomlc99
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
|
@ -109,6 +109,8 @@ TOML_EXTERN toml_table_t* toml_table_at(const toml_array_t* arr, int idx);
|
|||
/* on tables: */
|
||||
/* ... retrieve the key in table at keyidx. Return 0 if out of range. */
|
||||
TOML_EXTERN const char* toml_key_in(const toml_table_t* tab, int keyidx);
|
||||
/* ... returns 1 if key exists in tab, 0 otherwise */
|
||||
TOML_EXTERN int toml_key_exists(const toml_table_t* tab, const char* key);
|
||||
/* ... retrieve values using key. */
|
||||
TOML_EXTERN toml_datum_t toml_string_in(const toml_table_t* arr, const char* key);
|
||||
TOML_EXTERN toml_datum_t toml_bool_in(const toml_table_t* arr, const char* key);
|
||||
|
|
Loading…
Reference in a new issue