forked from qt-creator/qt-creator
Utils: Add a workaround for deprecated QTextCodec::setCodecForLocale
Change-Id: I5252164c46de1c29f1af45b89a186caace36259e Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -9,6 +9,19 @@
|
||||
|
||||
namespace Utils {
|
||||
|
||||
// TextEncoding
|
||||
|
||||
TextEncoding::TextEncoding(const QByteArray &name)
|
||||
: m_name(name)
|
||||
{}
|
||||
|
||||
TextEncoding::TextEncoding(QStringConverter::Encoding encoding)
|
||||
: m_name(QStringConverter::nameForEncoding(encoding))
|
||||
{}
|
||||
|
||||
|
||||
// TextCodec
|
||||
|
||||
TextCodec::TextCodec() = default;
|
||||
|
||||
TextCodec::TextCodec(QTextCodec *codec)
|
||||
@@ -106,9 +119,17 @@ TextCodec TextCodec::latin1()
|
||||
return theLatin1Codec;
|
||||
}
|
||||
|
||||
static TextEncoding theEncodingForLocale = TextEncoding(QStringEncoder::System);
|
||||
|
||||
void TextCodec::setCodecForLocale(const QByteArray &codecName)
|
||||
{
|
||||
QTextCodec::setCodecForLocale(QTextCodec::codecForName(codecName));
|
||||
theEncodingForLocale = codecName;
|
||||
}
|
||||
|
||||
TextEncoding TextCodec::encodingForLocale()
|
||||
{
|
||||
return theEncodingForLocale;
|
||||
}
|
||||
|
||||
QByteArray TextCodec::fromUnicode(QStringView data) const
|
||||
|
@@ -14,6 +14,19 @@ QT_END_NAMESPACE
|
||||
|
||||
namespace Utils {
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT TextEncoding
|
||||
{
|
||||
public:
|
||||
TextEncoding(const QByteArray &name);
|
||||
TextEncoding(QStringEncoder::Encoding encoding);
|
||||
|
||||
operator QByteArray() const { return m_name; }
|
||||
QByteArray name() const { return m_name; }
|
||||
|
||||
private:
|
||||
QByteArray m_name;
|
||||
};
|
||||
|
||||
class QTCREATOR_UTILS_EXPORT TextCodec final
|
||||
{
|
||||
public:
|
||||
@@ -52,6 +65,7 @@ public:
|
||||
static TextCodec latin1();
|
||||
|
||||
static void setCodecForLocale(const QByteArray &codecName);
|
||||
static TextEncoding encodingForLocale();
|
||||
|
||||
private:
|
||||
explicit TextCodec(QTextCodec *codec);
|
||||
|
Reference in New Issue
Block a user