LeechCraft  0.6.70-18450-gabe19ee3b0
Modular cross-platform feature rich live environment.
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 
11 namespace 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 
40  QString EncodingConverter::GetName () const
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 }
std::string Name_
STL namespace.
QByteArray FromUnicode(QStringView string)
QString ToUnicode(QByteArrayView bytes)