| 1 |
// This file is part of go-properties-orderedmap library. |
| 2 |
// |
| 3 |
// SPDX-FileCopyrightText: Arduino s.r.l. and/or its affiliated companies |
| 4 |
// SPDX-License-Identifier: GPL-2.0-or-later |
| 5 |
|
| 6 |
package properties |
| 7 |
|
| 8 |
import ( |
| 9 |
"strings" |
| 10 |
|
| 11 |
"github.com/arduino/go-paths-helper" |
| 12 |
) |
| 13 |
|
| 14 |
// GetBoolean returns true if the map contains the specified key and the value |
| 15 |
// equals to the string "true", in any other case returns false. |
| 16 |
func (m *Map) GetBoolean(key string) bool { |
| 17 |
value, ok := m.GetOk(key) |
| 18 |
return ok && strings.TrimSpace(value) == "true" |
| 19 |
} |
| 20 |
|
| 21 |
// SetBoolean sets the specified key to the string "true" or "false" if the value |
| 22 |
// is respectively true or false. |
| 23 |
func (m *Map) SetBoolean(key string, value bool) { |
| 24 |
if value { |
| 25 |
m.Set(key, "true") |
| 26 |
} else { |
| 27 |
m.Set(key, "false") |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
// GetPath returns a paths.Path object using the map value as path. The function |
| 32 |
// returns nil if the key is not present. |
| 33 |
func (m *Map) GetPath(key string) *paths.Path { |
| 34 |
value, ok := m.GetOk(key) |
| 35 |
if !ok { |
| 36 |
return nil |
| 37 |
} |
| 38 |
return paths.New(value) |
| 39 |
} |
| 40 |
|
| 41 |
// SetPath saves the paths.Path object in the map using the path as value of the map |
| 42 |
func (m *Map) SetPath(key string, value *paths.Path) { |
| 43 |
if value == nil { |
| 44 |
m.Set(key, "") |
| 45 |
} else { |
| 46 |
m.Set(key, value.String()) |
| 47 |
} |
| 48 |
} |