Skip to content

Commit 53dddce

Browse files
committed
bon++
1 parent 551e149 commit 53dddce

File tree

2 files changed

+40
-16
lines changed

2 files changed

+40
-16
lines changed

inc/mkn/kul/bon.hpp

+21-16
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,17 @@ class ob {
8181

8282
private:
8383
static void BUILD(BonParsableNode const& node, ob& o) {
84-
KLOG(INF) << node.ss.str() << " " << o.p;
85-
8684
if (!node.nodes.size())
8785
o.a = node.ss.str();
8886
else
8987
o.v = node.ss.str();
9088

9189
mkn::kul::String::TRIM(o.a);
9290
mkn::kul::String::TRIM(o.v);
93-
if (o.v.back() == ':')) {
94-
o.v = o.v.substr(0, o.v.size() - 1);
95-
mkn::kul::String::TRIM(o.v);
96-
}
91+
if (o.v.back() == ':') {
92+
o.v = o.v.substr(0, o.v.size() - 1);
93+
mkn::kul::String::TRIM(o.v);
94+
}
9795

9896
for (auto const& n : node.nodes) {
9997
o.c.emplace_back().p = &o;
@@ -113,15 +111,25 @@ class ob {
113111
auto vals = mkn::kul::String::ESC_SPLIT(o.a, ',');
114112
if (o.a.find(":") == std::string::npos) { // list
115113

116-
for (std::size_t i = 0; i < vals.size(); ++i) {
117-
auto p = mkn::kul::String::ESC_SPLIT(vals[i], ':');
118-
KLOG(INF) << p[0];
114+
if (vals.size() == 1) {
115+
auto p = mkn::kul::String::ESC_SPLIT(vals[0], ':');
116+
119117
if (p.size() == 1) {
120118
mkn::kul::String::TRIM(p);
121-
n.push_back(p[0]);
119+
n = p[0];
122120
} else
123121
KEXCEPTION("FAIL");
124-
}
122+
123+
} else
124+
for (std::size_t i = 0; i < vals.size(); ++i) {
125+
auto p = mkn::kul::String::ESC_SPLIT(vals[i], ':');
126+
127+
if (p.size() == 1) {
128+
mkn::kul::String::TRIM(p);
129+
n.push_back(p[0]);
130+
} else
131+
KEXCEPTION("FAIL");
132+
}
125133
} else // map
126134
for (auto const& v : vals) {
127135
auto p = mkn::kul::String::ESC_SPLIT(v, ':');
@@ -178,11 +186,8 @@ YAML::Node from(std::string const& s) {
178186

179187
if (open) c_check();
180188
for (auto const& o : obs) nodes.emplace_back(o.to_yaml());
181-
auto const ret = YAML::Node(nodes);
182-
YAML::Emitter out;
183-
out << ret;
184-
KLOG(INF) << out.c_str();
185-
return ret;
189+
assert(obs.size() == 1);
190+
return obs[0].to_yaml();
186191
}
187192

188193
} // namespace bon

test/test_yaml/bon.cpp

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
2+
3+
#include "gtest/gtest.h"
4+
5+
#include "mkn/kul/bon.hpp"
6+
7+
TEST(Bon, parseString) {
8+
auto node = mkn::kul::bon::from("{rofl:{copter}}");
9+
10+
for (auto const& el : node) {
11+
EXPECT_EQ(el.first.as<std::string>(), "rofl");
12+
EXPECT_EQ(el.second.as<std::string>(), "copter");
13+
}
14+
}
15+
16+
int main(int argc, char* argv[]) {
17+
::testing::InitGoogleTest(&argc, argv);
18+
return RUN_ALL_TESTS();
19+
}

0 commit comments

Comments
 (0)