1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

toml: add as_strings() method to map of Any (#12824)

This commit is contained in:
Larpon 2021-12-13 20:43:33 +01:00 committed by GitHub
parent 76f6f99bce
commit 2a5356670b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -171,6 +171,16 @@ pub fn (m map[string]Any) value(key string) Any {
return Any(m).value(key)
}
// as_strings returns the contents of the map
// as `map[string]string`
pub fn (m map[string]Any) as_strings() map[string]string {
mut result := map[string]string{}
for k, v in m {
result[k] = v.string()
}
return result
}
// value queries a value from the array.
// `key` supports a small query syntax scheme:
// The array can be queried with `[0].b[1].[2]`.
@ -180,6 +190,8 @@ pub fn (a []Any) value(key string) Any {
return Any(a).value(key)
}
// as_strings returns the contents of the array
// as `[]string`
pub fn (a []Any) as_strings() []string {
mut sa := []string{}
for any in a {