Chatterino
RapidJsonSerializeQString.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <QString>
4 #include <pajlada/serialize.hpp>
5 
6 namespace pajlada {
7 
8 template <>
9 struct Serialize<QString> {
10  static rapidjson::Value get(const QString &value,
11  rapidjson::Document::AllocatorType &a)
12  {
13  return rapidjson::Value(value.toUtf8(), a);
14  }
15 };
16 
17 template <>
18 struct Deserialize<QString> {
19  static QString get(const rapidjson::Value &value, bool *error = nullptr)
20  {
21  if (!value.IsString())
22  {
23  PAJLADA_REPORT_ERROR(error)
24  return QString{};
25  }
26 
27  try
28  {
29  return QString::fromUtf8(value.GetString(),
30  value.GetStringLength());
31  }
32  catch (const std::exception &)
33  {
34  // int x = 5;
35  }
36  catch (...)
37  {
38  // int y = 5;
39  }
40 
41  return QString{};
42  }
43 };
44 
45 } // namespace pajlada
Definition: Command.hpp:25