| 224 | } |
| 225 | |
| 226 | FlattenedDocument parse_flattened_document(std::string_view text) { |
| 227 | require_single_document(text); |
| 228 | Parser parser(text); |
| 229 | yaml_document_t & document = parser.load_primary(); |
| 230 | |
| 231 | yaml_node_t * root = yaml_document_get_root_node(&document); |
| 232 | if (root == nullptr) { |
| 233 | return {}; |
| 234 | } |
| 235 | if (root->type != YAML_MAPPING_NODE) { |
| 236 | throw std::runtime_error("yaml config root must be a mapping"); |
| 237 | } |
| 238 | |
| 239 | FlattenedDocument flattened; |
| 240 | for (yaml_node_pair_t * pair = root->data.mapping.pairs.start; |
| 241 | pair != root->data.mapping.pairs.top; |
| 242 | ++pair) { |
| 243 | const std::string key = require_scalar_value(document, pair->key, "mapping key"); |
| 244 | if (key.empty()) { |
| 245 | continue; |
| 246 | } |
| 247 | flatten_node(document, pair->value, key, flattened); |
| 248 | } |
| 249 | return flattened; |
| 250 | } |
| 251 | |
| 252 | bool parse_bool_scalar(const std::string & value, const std::string & key) { |
| 253 | if (value == "true") { |
no test coverage detected