MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / parse_scalar_mapping

Function parse_scalar_mapping

src/framework/io/yaml.cpp:196–224  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

194} // namespace
195
196ConfigMap 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
226FlattenedDocument parse_flattened_document(std::string_view text) {
227 require_single_document(text);

Callers 1

load_config_mapFunction · 0.85

Calls 4

require_single_documentFunction · 0.85
require_scalar_valueFunction · 0.85
emptyMethod · 0.45

Tested by

no test coverage detected