|
| 1 | +// This file is part of arduino-lint. |
| 2 | +// |
| 3 | +// Copyright 2020 ARDUINO SA (http://www.arduino.cc/) |
| 4 | +// |
| 5 | +// This software is released under the GNU General Public License version 3, |
| 6 | +// which covers the main part of arduino-lint. |
| 7 | +// The terms of this license can be found at: |
| 8 | +// https://www.gnu.org/licenses/gpl-3.0.en.html |
| 9 | +// |
| 10 | +// You can be released from the requirements of the above licenses by purchasing |
| 11 | +// a commercial license. Buying such a license is mandatory if you want to |
| 12 | +// modify or otherwise use the software for commercial activities involving the |
| 13 | +// Arduino software without disclosing the source code of your own applications. |
| 14 | +// To purchase a commercial license, send an email to [email protected]. |
| 15 | + |
| 16 | +// Package general provides functions that apply to multiple project types. |
| 17 | +package general |
| 18 | + |
| 19 | +import ( |
| 20 | + "github.com/arduino/go-properties-orderedmap" |
| 21 | +) |
| 22 | + |
| 23 | +/* |
| 24 | +PropertiesToFirstLevelExpandedMap converts properties.Map data structures to map[string]interface that maps between . |
| 25 | +Even though boards/properties.txt have a multi-level nested data structure, the format has the odd characteristic of |
| 26 | +allowing a key to be both an object and a string simultaneously, which is not compatible with Golang maps or JSON. So |
| 27 | +the data structure used is a map of the first level keys (necessary to accommodate the board/prograrmmer IDs) to the |
| 28 | +full remainder of the keys (rather than recursing through each key level individually), to string values. |
| 29 | +*/ |
| 30 | +func PropertiesToFirstLevelExpandedMap(flatProperties *properties.Map) map[string]interface{} { |
| 31 | + propertiesInterface := make(map[string]interface{}) |
| 32 | + keys := flatProperties.FirstLevelKeys() |
| 33 | + for _, key := range keys { |
| 34 | + subtreeMap := flatProperties.SubTree(key).AsMap() |
| 35 | + // This level also must be converted to map[string]interface{}. |
| 36 | + subtreeInterface := make(map[string]interface{}) |
| 37 | + for subtreeKey, subtreeValue := range subtreeMap { |
| 38 | + subtreeInterface[subtreeKey] = subtreeValue |
| 39 | + } |
| 40 | + propertiesInterface[key] = subtreeInterface |
| 41 | + } |
| 42 | + |
| 43 | + return propertiesInterface |
| 44 | +} |
0 commit comments