Strip redundant newline in repr() for taxonomy items

E.g.
print([m.diffuse for m in shape.geometry.materials])

would print
[colour 0.7 0.7 0.7
]

Instead of:
[colour 0.7 0.7 0.7]
This commit is contained in:
Andrej730
2024-09-05 11:16:22 +05:00
parent deb41d2158
commit 051d5479fb
+8 -1
View File
@@ -151,7 +151,14 @@ std::pair<char const*, size_t> vector_to_buffer(const T& t) {
std::string taxonomy_item_repr(ifcopenshell::geometry::taxonomy::item::ptr i) {
std::ostringstream oss;
i->print(oss);
return oss.str();
std::string result = oss.str();
// Strip new line at the end of the printed result.
// result is probably always ends with \n but just to be safe.
if (!result.empty() && result.back() == '\n') {
result.pop_back();
}
return result;
}
%}