Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions include/kvpp/KV1.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,10 @@ class KV1 : public KV1ElementReadable<S> {
explicit KV1(std::string_view kv1Data, bool useEscapeSequences_ = false)
: KV1ElementReadable<S>()
, useEscapeSequences(useEscapeSequences_) {
// Skip the UTF-8 BOM
if (kv1Data.starts_with("\xEF\xBB\xBF")) {
kv1Data.remove_prefix(3);
}
if (kv1Data.empty()) {
return;
}
Expand Down
4 changes: 4 additions & 0 deletions include/kvpp/KV1Writer.h
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ class KV1Writer : public KV1ElementWritable<S> {
explicit KV1Writer(std::string_view kv1Data = "", bool useEscapeSequences_ = false)
: KV1ElementWritable<S>()
, useEscapeSequences(useEscapeSequences_) {
// Skip the UTF-8 BOM
if (kv1Data.starts_with("\xEF\xBB\xBF")) {
kv1Data.remove_prefix(3);
}
if (kv1Data.empty()) {
return;
}
Expand Down
18 changes: 9 additions & 9 deletions lang/python/src/kvpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ inline void register_python(py::module_& m) {
.def_prop_rw("uuid", &DMXElement::getUUID, &DMXElement::setUUID)
.def("has_attribute", &DMXElement::hasAttribute, "attribute_key"_a)
.def("__contains__", &DMXElement::hasAttribute, "attribute_key"_a)
.def("add_attribute", &DMXElement::addAttribute, "key"_a, "value"_a = DMXValue::Generic{}, py::rv_policy::reference_internal)
.def("add_attribute", &DMXElement::addAttribute, "key"_a, "value"_a.none() = DMXValue::Generic{}, py::rv_policy::reference_internal)
.def("get_attribute_count", py::overload_cast<>(&DMXElement::getAttributeCount, py::const_))
.def("__len__", py::overload_cast<>(&DMXElement::getAttributeCount, py::const_))
.def("get_attribute_count_with_key", py::overload_cast<std::string_view>(&DMXElement::getAttributeCount, py::const_))
Expand All @@ -248,7 +248,7 @@ inline void register_python(py::module_& m) {
}, py::keep_alive<0, 1>())
.def("__getitem__", py::overload_cast<unsigned int>(&DMXElement::operator[]), "n"_a, py::rv_policy::reference_internal)
.def("__getitem__", py::overload_cast<std::string_view>(&DMXElement::operator[]), "attribute_key"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&DMXElement::operator()), "attribute_key"_a, "n"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&DMXElement::operator()), "attribute_key"_a, "n"_a = 0, py::rv_policy::reference_internal)
.def("remove_child", py::overload_cast<unsigned int>(&DMXElement::removeAttribute), "n"_a)
.def("__delitem__", py::overload_cast<unsigned int>(&DMXElement::removeAttribute), "n"_a)
.def("remove_child", py::overload_cast<std::string_view, int>(&DMXElement::removeAttribute), "attribute_key"_a, "n"_a = -1)
Expand All @@ -271,7 +271,7 @@ inline void register_python(py::module_& m) {
cDMX
.def(py::init<DMX::Encoding, int, std::string, int>(), "encoding_type"_a, "encoding_version"_a, "format_type"_a, "format_version"_a)
.def("__init__", [](DMX* self, const py::bytes& dmxData) {
return new(self) DMX{std::span{static_cast<const std::byte*>(dmxData.data()), dmxData.size()}};
new(self) DMX{std::span{static_cast<const std::byte*>(dmxData.data()), dmxData.size()}};
}, "dmx_data"_a)
.def(py::init<std::string_view>(), "dmx_data"_a)
.def("__bool__", &DMX::operator bool)
Expand All @@ -296,7 +296,7 @@ inline void register_python(py::module_& m) {
}, py::keep_alive<0, 1>())
.def("__getitem__", py::overload_cast<unsigned int>(&DMX::operator[]), "n"_a, py::rv_policy::reference_internal)
.def("__getitem__", py::overload_cast<std::string_view>(&DMX::operator[]), "key"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&DMX::operator()), "key"_a, "n"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&DMX::operator()), "key"_a, "n"_a = 0, py::rv_policy::reference_internal)
.def("remove_child", py::overload_cast<unsigned int>(&DMX::removeElement), "n"_a)
.def("__delitem__", py::overload_cast<unsigned int>(&DMX::removeElement), "n"_a)
.def("bake", [](const DMX& self) {
Expand Down Expand Up @@ -325,7 +325,7 @@ inline void register_python(py::module_& m) {
}, py::keep_alive<0, 1>())
.def("__getitem__", py::overload_cast<unsigned int>(&KV1ElementReadable<>::operator[], py::const_), "n"_a, py::rv_policy::reference_internal)
.def("__getitem__", py::overload_cast<std::string_view>(&KV1ElementReadable<>::operator[], py::const_), "child_key"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1ElementReadable<>::operator(), py::const_), "child_key"_a, "n"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1ElementReadable<>::operator(), py::const_), "child_key"_a, "n"_a = 0, py::rv_policy::reference_internal)
.def("is_invalid", &KV1ElementReadable<>::isInvalid)
.def("get_invalid", &KV1ElementReadable<>::getInvalid)
.def("__bool__", &KV1ElementReadable<>::operator bool);
Expand All @@ -351,7 +351,7 @@ inline void register_python(py::module_& m) {
}, py::keep_alive<0, 1>())
.def("__getitem__", py::overload_cast<unsigned int>(&KV1ElementWritable<>::operator[]), "n"_a, py::rv_policy::reference_internal)
.def("__getitem__", py::overload_cast<std::string_view>(&KV1ElementWritable<>::operator[]), "child_key"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1ElementWritable<>::operator()), "child_key"_a, "n"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1ElementWritable<>::operator()), "child_key"_a, "n"_a = 0, py::rv_policy::reference_internal)
.def("remove_child", py::overload_cast<unsigned int>(&KV1ElementWritable<>::removeChild), "n"_a)
.def("__delitem__", py::overload_cast<unsigned int>(&KV1ElementWritable<>::removeChild), "n"_a)
.def("remove_child", py::overload_cast<std::string_view, int>(&KV1ElementWritable<>::removeChild), "child_key"_a, "n"_a = -1)
Expand Down Expand Up @@ -395,7 +395,7 @@ inline void register_python(py::module_& m) {
.def("__contains__", &KV1BinaryElement::hasChild, "child_key"_a)
.def("add_child", [](KV1BinaryElement& self, std::string_view key, KV1BinaryValue value = {}) -> KV1BinaryElement& {
return self.addChild(key, std::move(value));
}, "key"_a, "value"_a = KV1BinaryValue{}, py::rv_policy::reference_internal)
}, "key"_a, "value"_a.none() = KV1BinaryValue{}, py::rv_policy::reference_internal)
.def_prop_ro("child_count", py::overload_cast<>(&KV1BinaryElement::getChildCount, py::const_))
.def("__len__", py::overload_cast<>(&KV1BinaryElement::getChildCount, py::const_))
.def("get_child_count_with_key", py::overload_cast<std::string_view>(&KV1BinaryElement::getChildCount, py::const_), "child_key"_a)
Expand All @@ -405,7 +405,7 @@ inline void register_python(py::module_& m) {
}, py::keep_alive<0, 1>())
.def("__getitem__", py::overload_cast<unsigned int>(&KV1BinaryElement::operator[]), "n"_a, py::rv_policy::reference_internal)
.def("__getitem__", py::overload_cast<std::string_view>(&KV1BinaryElement::operator[]), "child_key"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1BinaryElement::operator()), "child_key"_a, "n"_a, py::rv_policy::reference_internal)
.def("get_child", py::overload_cast<std::string_view, unsigned int>(&KV1BinaryElement::operator()), "child_key"_a, "n"_a = 0, py::rv_policy::reference_internal)
.def("remove_child", py::overload_cast<unsigned int>(&KV1BinaryElement::removeChild), "n"_a)
.def("__delitem__", py::overload_cast<unsigned int>(&KV1BinaryElement::removeChild), "n"_a)
.def("remove_child", py::overload_cast<std::string_view, int>(&KV1BinaryElement::removeChild), "child_key"_a, "n"_a = -1)
Expand All @@ -415,7 +415,7 @@ inline void register_python(py::module_& m) {

py::class_<KV1Binary, KV1BinaryElement>(kvpp, "KV1Binary")
.def("__init__", [](KV1Binary* self, const py::bytes& kv1Data, bool use64BitPointers = true) {
return new(self) KV1Binary{std::span{static_cast<const std::byte*>(kv1Data.data()), kv1Data.size()}, use64BitPointers};
new(self) KV1Binary{std::span{static_cast<const std::byte*>(kv1Data.data()), kv1Data.size()}, use64BitPointers};
}, "kv1_data"_a, "use_64_bit_pointers"_a = true)
.def("bake", [](const KV1Binary& self) {
const auto d = self.bake();
Expand Down
14 changes: 7 additions & 7 deletions lang/python/src/vtfpp.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ inline void register_python(py::module_& m) {
cHOT
.def(py::init())
.def("__init__", [](HOT* self, const py::bytes& hotData) {
return new(self) HOT{{static_cast<const std::byte*>(hotData.data()), hotData.size()}};
new(self) HOT{{static_cast<const std::byte*>(hotData.data()), hotData.size()}};
}, "hot_data"_a)
.def(py::init<const std::filesystem::path&>(), "hot_path"_a)
.def("__bool__", &HOT::operator bool, py::is_operator())
Expand Down Expand Up @@ -369,7 +369,7 @@ inline void register_python(py::module_& m) {
cPPL
.def(py::init<uint32_t, ImageFormat, uint32_t>(), "model_checksum"_a, "format"_a = ImageFormat::RGB888, "version"_a = 0)
.def("__init__", [](PPL* self, const py::bytes& pplData) {
return new(self) PPL{{static_cast<const std::byte*>(pplData.data()), pplData.size()}};
new(self) PPL{{static_cast<const std::byte*>(pplData.data()), pplData.size()}};
}, "ppl_data"_a)
.def(py::init<const std::filesystem::path&>(), "path"_a)
.def("__bool__", &PPL::operator bool, py::is_operator())
Expand Down Expand Up @@ -409,7 +409,7 @@ inline void register_python(py::module_& m) {

py::class_<PSFrames>(vtfpp, "PSFrames")
.def("__init__", [](PSFrames* self, const py::bytes& psFramesData) {
return new(self) PSFrames{std::span{static_cast<const std::byte*>(psFramesData.data()), psFramesData.size()}};
new(self) PSFrames{std::span{static_cast<const std::byte*>(psFramesData.data()), psFramesData.size()}};
}, "ps_frames_data"_a)
.def(py::init<const std::filesystem::path&>(), "ps_frames_path"_a)
.def("__bool__", &PSFrames::operator bool, py::is_operator())
Expand Down Expand Up @@ -462,7 +462,7 @@ inline void register_python(py::module_& m) {
cSHT
.def(py::init())
.def("__init__", [](SHT* self, const py::bytes& shtData) {
return new(self) SHT{{static_cast<const std::byte*>(shtData.data()), shtData.size()}};
new(self) SHT{{static_cast<const std::byte*>(shtData.data()), shtData.size()}};
}, "sht_data"_a)
.def(py::init<const std::filesystem::path&>(), "sht_path"_a)
.def("__bool__", &SHT::operator bool, py::is_operator())
Expand All @@ -483,7 +483,7 @@ inline void register_python(py::module_& m) {
py::class_<TTX>(vtfpp, "TTX")
.def(py::init<VTF&&>(), "vtf"_a)
.def("__init__", [](TTX* self, const py::bytes& tthData, const py::bytes& ttzData) {
return new(self) TTX{{static_cast<const std::byte*>(tthData.data()), tthData.size()}, {static_cast<const std::byte*>(ttzData.data()), ttzData.size()}};
new(self) TTX{{static_cast<const std::byte*>(tthData.data()), tthData.size()}, {static_cast<const std::byte*>(ttzData.data()), ttzData.size()}};
}, "tth_data"_a, "ttz_data"_a)
.def(py::init<const std::filesystem::path&, const std::filesystem::path&>(), "tth_path"_a, "ttz_path"_a)
.def("__bool__", &TTX::operator bool, py::is_operator())
Expand Down Expand Up @@ -525,7 +525,7 @@ inline void register_python(py::module_& m) {

cVBF
.def("__init__", [](VBF* self, const py::bytes& vbfData) {
return new(self) VBF{std::span{static_cast<const std::byte*>(vbfData.data()), vbfData.size()}};
new(self) VBF{std::span{static_cast<const std::byte*>(vbfData.data()), vbfData.size()}};
}, "vbf_data"_a)
.def(py::init<const std::filesystem::path&>(), "vbf_path"_a)
.def("__bool__", &VBF::operator bool)
Expand Down Expand Up @@ -697,7 +697,7 @@ inline void register_python(py::module_& m) {
.def_ro_static("FORMAT_DEFAULT", &VTF::FORMAT_DEFAULT)
.def(py::init())
.def("__init__", [](VTF* self, const py::bytes& vtfData, bool parseHeaderOnly = false, bool hdr = false) {
return new(self) VTF{std::span{static_cast<const std::byte*>(vtfData.data()), vtfData.size()}, parseHeaderOnly, hdr};
new(self) VTF{std::span{static_cast<const std::byte*>(vtfData.data()), vtfData.size()}, parseHeaderOnly, hdr};
}, "vtf_data"_a, "parse_header_only"_a = false, "hdr"_a = false)
.def(py::init<const std::filesystem::path&, bool>(), "vtf_path"_a, "parse_header_only"_a = false)
.def("__bool__", &VTF::operator bool, py::is_operator())
Expand Down
Loading