slight change in returning timestamp. now returns a malloc-ed ptr
This commit is contained in:
parent
893f24e206
commit
94136b9f04
2 changed files with 17 additions and 3 deletions
18
toml.c
18
toml.c
|
@ -2195,11 +2195,18 @@ toml_datum_t toml_double_at(const toml_array_t* arr, int idx)
|
|||
|
||||
toml_datum_t toml_timestamp_at(const toml_array_t* arr, int idx)
|
||||
{
|
||||
toml_timestamp_t ts;
|
||||
toml_datum_t ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
toml_raw_t raw = toml_raw_at(arr, idx);
|
||||
if (raw) {
|
||||
ret.ok = (0 == toml_rtots(raw, &ret.u.ts));
|
||||
ret.ok = (0 == toml_rtots(raw, &ts));
|
||||
if (ret.ok) {
|
||||
ret.ok = !!(ret.u.ts = malloc(sizeof(*ret.u.ts)));
|
||||
if (ret.ok) {
|
||||
*ret.u.ts = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -2250,11 +2257,18 @@ toml_datum_t toml_double_in(const toml_table_t* arr, const char* key)
|
|||
|
||||
toml_datum_t toml_timestamp_in(const toml_table_t* arr, const char* key)
|
||||
{
|
||||
toml_timestamp_t ts;
|
||||
toml_datum_t ret;
|
||||
memset(&ret, 0, sizeof(ret));
|
||||
toml_raw_t raw = toml_raw_in(arr, key);
|
||||
if (raw) {
|
||||
ret.ok = (0 == toml_rtots(raw, &ret.u.ts));
|
||||
ret.ok = (0 == toml_rtots(raw, &ts));
|
||||
if (ret.ok) {
|
||||
ret.ok = !!(ret.u.ts = malloc(sizeof(*ret.u.ts)));
|
||||
if (ret.ok) {
|
||||
*ret.u.ts = ts;
|
||||
}
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
|
2
toml.h
2
toml.h
|
@ -85,11 +85,11 @@ struct toml_timestamp_t {
|
|||
struct toml_datum_t {
|
||||
int ok;
|
||||
union {
|
||||
toml_timestamp_t* ts; /* ts must be freed after use */
|
||||
char* s; /* string value. s must be freed after use */
|
||||
int b; /* bool value */
|
||||
int64_t i; /* int value */
|
||||
double d; /* double value */
|
||||
toml_timestamp_t ts;
|
||||
} u;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue