-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathyaml.cpp
33 lines (28 loc) · 786 Bytes
/
yaml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <stdexcept>
#include <yaml.h>
#include "wrappers.h"
yaml_node_t *get_mapping_entry(
yaml_document_t *document,
yaml_node_t *mapping,
const char *name
) {
if (!mapping) {
return nullptr;
}
for (const auto &pair : yaml_mapping_wrapper{document, mapping}) {
const auto &key = pair.first;
if (!key || key->type != YAML_SCALAR_NODE) {
return nullptr;
}
if (strncmp((const char *) key->data.scalar.value, name, key->data.scalar.length) != 0) {
continue;
}
return pair.second;
}
return nullptr;
}
void require_type(yaml_node_t *node, yaml_node_type_t type) {
if (node->type != type) {
throw std::runtime_error{"Unexpected node type"};
}
}