From 12eca108a07cde1606fca3e472aed58749407699 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sat, 5 Nov 2022 19:29:40 +0100 Subject: replace std::string with Corrade's String --- serialize/string.cpp | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 serialize/string.cpp (limited to 'serialize/string.cpp') diff --git a/serialize/string.cpp b/serialize/string.cpp new file mode 100644 index 00000000..0c0fa74e --- /dev/null +++ b/serialize/string.cpp @@ -0,0 +1,39 @@ +#include "string.hpp" +#include +#include +#include + +using String = Corrade::Containers::String; +using StringView = Corrade::Containers::StringView; + +namespace nlohmann { + +void adl_serializer::to_json(json& j, const String& val) +{ + using nlohmann::to_json; + to_json(j, std::string_view { val.cbegin(), val.cend() }); +} + +void adl_serializer::from_json(const json& j, String& val) +{ + using nlohmann::from_json; + std::string_view str; + from_json(j, str); + val = { str.cbegin(), str.size() }; +} + +void adl_serializer::to_json(json& j, const StringView& val) +{ + using nlohmann::to_json; + to_json(j, std::string_view { val.cbegin(), val.cend() }); +} + +void adl_serializer::from_json(const json& j, StringView& val) +{ + using nlohmann::from_json; + std::string_view str; + from_json(j, str); + val = { str.cbegin(), str.size() }; +} + +} // namespace nlohmann -- cgit v1.2.3