LeechCraft
0.6.70-16373-g319c272718
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
Either<QString, QJsonDocument>::Right
(
doc
);
22
return
Either<QString, QJsonDocument>::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:22
LC::Util::Either::Left
static Either Left(const L &l)
Definition
either.h:119
LC::Util::Either::Right
static Either Right(R &&r)
Definition
either.h:124
LC::Util::UnexpectedJson::UnexpectedJson
UnexpectedJson(QJsonValue::Type expected, const QJsonValue &)
Definition
json.cpp:36
json.h
LC::Util
Definition
icoreproxy.h:34
LC::Util::Filter
Container< T > Filter(const Container< T > &c, F f)
Definition
prelude.h:118
LC::Util::ToJson
Either< QString, QJsonDocument > ToJson(const QByteArray &json)
Definition
json.cpp:16
std
STL namespace.
either.h
src
util
sll
json.cpp
Generated by
1.10.0