LeechCraft
0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
json.cpp
Go to the documentation of this file.
1
/**********************************************************************
2
* LeechCraft - modular cross-platform feature rich internet client.
3
* Copyright (C) 2006-2014 Georg Rudoy
4
*
5
* Distributed under the Boost Software License, Version 1.0.
6
* (See accompanying file LICENSE or copy at https://www.boost.org/LICENSE_1_0.txt)
7
**********************************************************************/
8
9
#include "
json.h
"
10
#include <QJsonDocument>
11
#include <QtDebug>
12
#include "
either.h
"
13
14
namespace
LC::Util
15
{
16
Either<QString, QJsonDocument>
ToJson
(
const
QByteArray& json)
17
{
18
QJsonParseError error;
19
auto
doc = QJsonDocument::fromJson (json, &error);
20
if
(error.error == QJsonParseError::NoError)
21
return
{ doc };
22
return
Left
{ error.errorString () };
23
}
24
25
namespace
26
{
27
std::string MakeUnexpectedMessage (QJsonValue::Type expected,
const
auto
& value)
28
{
29
QString result;
30
QDebug dbg { &result };
31
dbg <<
"unexpected JSON: expected"
<< expected <<
"but got"
<< value;
32
return
result.toStdString ();
33
}
34
}
35
36
UnexpectedJson::UnexpectedJson
(QJsonValue::Type expected,
const
QJsonValue& value)
37
: std::runtime_error { MakeUnexpectedMessage (expected, value) }
38
{
39
}
40
41
UnexpectedJson::UnexpectedJson
(QJsonValue::Type expected,
const
QJsonDocument& doc)
42
: std::runtime_error { MakeUnexpectedMessage (expected, doc) }
43
{
44
}
45
}
LC::Util::Either
Definition
either.h:33
LC::Util::UnexpectedJson::UnexpectedJson
UnexpectedJson(QJsonValue::Type expected, const QJsonValue &)
Definition
json.cpp:36
json.h
LC::Util
Definition
icoreproxy.h:34
LC::Util::ToJson
Either< QString, QJsonDocument > ToJson(const QByteArray &json)
Definition
json.cpp:16
either.h
LC::Util::Left
Definition
either.h:22
src
util
sll
json.cpp
Generated by
1.13.2