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

pull/12829/head
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
1 changed files with 12 additions and 0 deletions

View File

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