LeechCraft 0.6.70-17609-g3dde4097dd
Modular cross-platform feature rich live environment.
Loading...
Searching...
No Matches
encodingconverter.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 "encodingconverter.h"
10
11namespace LC::Util
12{
14 : std::runtime_error { "unknown encoding " + encoding.toStdString () }
15 , Encoding_ { encoding }
16 {
17 }
18
20 {
21 return Encoding_;
22 }
23
25 : Name_ { "System" }
26 , Encoder_ { QStringConverter::System }
27 , Decoder_ { QStringConverter::System }
28 {
29 }
30
31 EncodingConverter::EncodingConverter (QAnyStringView encoding)
32 : Name_ { encoding.toString () }
33 , Encoder_ { encoding }
34 , Decoder_ { encoding }
35 {
36 if (!Encoder_.isValid () || !Decoder_.isValid ())
37 throw UnknownEncoding { Name_ };
38 }
39
41 {
42 return Name_;
43 }
44
45 QString EncodingConverter::ToUnicode (QByteArrayView bytes)
46 {
47 return Decoder_.decode (bytes);
48 }
49
50 QByteArray EncodingConverter::FromUnicode (QStringView string)
51 {
52 return Encoder_.encode (string);
53 }
54}
QString ToUnicode(QByteArrayView bytes)
QByteArray FromUnicode(QStringView string)
char * toString(const char *name, const T &t)
Definition common.h:55