summaryrefslogtreecommitdiffhomepage
path: root/serialize/string.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-11-05 19:29:40 +0100
committerStanislaw Halik <sthalik@misaki.pl>2022-11-05 19:29:40 +0100
commit12eca108a07cde1606fca3e472aed58749407699 (patch)
tree44ac90dffca8cde0fc06800c5546cd12f5cd9249 /serialize/string.cpp
parent28f5a46ba0058752d4e92cc66e0260f4ed2b8cf3 (diff)
replace std::string with Corrade's String
Diffstat (limited to 'serialize/string.cpp')
-rw-r--r--serialize/string.cpp39
1 files changed, 39 insertions, 0 deletions
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 <Corrade/Containers/String.h>
+#include <string_view>
+#include <nlohmann/json.hpp>
+
+using String = Corrade::Containers::String;
+using StringView = Corrade::Containers::StringView;
+
+namespace nlohmann {
+
+void adl_serializer<String>::to_json(json& j, const String& val)
+{
+ using nlohmann::to_json;
+ to_json(j, std::string_view { val.cbegin(), val.cend() });
+}
+
+void adl_serializer<String>::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<StringView>::to_json(json& j, const StringView& val)
+{
+ using nlohmann::to_json;
+ to_json(j, std::string_view { val.cbegin(), val.cend() });
+}
+
+void adl_serializer<StringView>::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