summaryrefslogtreecommitdiffhomepage
path: root/serialize/string.cpp
blob: 0c0fa74ecb7ceb7cc77c37c00f3eec7a45ef61f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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