| 194 | } // namespace |
| 195 | |
| 196 | ConfigMap parse_scalar_mapping(std::string_view text) { |
| 197 | require_single_document(text); |
| 198 | Parser parser(text); |
| 199 | yaml_document_t & document = parser.load_primary(); |
| 200 | |
| 201 | yaml_node_t * root = yaml_document_get_root_node(&document); |
| 202 | if (root == nullptr) { |
| 203 | return {}; |
| 204 | } |
| 205 | if (root->type != YAML_MAPPING_NODE) { |
| 206 | throw std::runtime_error("yaml config root must be a mapping"); |
| 207 | } |
| 208 | |
| 209 | ConfigMap config; |
| 210 | const auto pair_count = static_cast<size_t>(root->data.mapping.pairs.top - root->data.mapping.pairs.start); |
| 211 | config.reserve(pair_count); |
| 212 | |
| 213 | for (yaml_node_pair_t * pair = root->data.mapping.pairs.start; |
| 214 | pair != root->data.mapping.pairs.top; |
| 215 | ++pair) { |
| 216 | const std::string key = require_scalar_value(document, pair->key, "mapping key"); |
| 217 | const std::string value = require_scalar_value(document, pair->value, "mapping value for key '" + key + "'"); |
| 218 | if (!key.empty()) { |
| 219 | config[key] = value; |
| 220 | } |
| 221 | } |
| 222 | |
| 223 | return config; |
| 224 | } |
| 225 | |
| 226 | FlattenedDocument parse_flattened_document(std::string_view text) { |
| 227 | require_single_document(text); |
no test coverage detected