QGIS API Documentation
4.3.0-Master (16eddb2670e)
Toggle main menu visibility
Loading...
Searching...
No Matches
src
core
qgsogrproxytextcodec.cpp
Go to the documentation of this file.
1
/***************************************************************************
2
qgsogrproxytextcodec.cpp
3
-------------
4
begin : June 2020
5
copyright : (C) 2020 Nyall Dawson
6
email : nyall dot dawson at gmail dot com
7
***************************************************************************
8
* *
9
* This program is free software; you can redistribute it and/or modify *
10
* it under the terms of the GNU General Public License as published by *
11
* the Free Software Foundation; either version 2 of the License, or *
12
* (at your option) any later version. *
13
* *
14
***************************************************************************/
15
16
#include "
qgsogrproxytextcodec.h
"
17
18
#include <cpl_string.h>
19
#include <mutex>
20
21
#include "
qgslogger.h
"
22
23
#include <QString>
24
25
using namespace
Qt::StringLiterals;
26
27
QgsOgrProxyTextCodec::QgsOgrProxyTextCodec
(
const
QByteArray &
name
)
28
: mName(
name
)
29
{}
30
31
QString
QgsOgrProxyTextCodec::convertToUnicode
(
const
char
*chars,
int
, ConverterState * )
const
32
{
33
if
( !chars )
34
return
QString();
35
36
char
*res = CPLRecode( chars, mName.constData(), CPL_ENC_UTF8 );
37
if
( !res )
38
{
39
QgsDebugError
(
"convertToUnicode failed"
);
40
return
QString();
41
}
42
43
const
QString result = QString::fromUtf8( res );
44
CPLFree( res );
45
return
result;
46
}
47
48
QByteArray
QgsOgrProxyTextCodec::convertFromUnicode
(
const
QChar *unicode,
int
length, ConverterState * )
const
49
{
50
if
( !unicode )
51
return
QByteArray();
52
53
const
QString src = QString( unicode, length );
54
char
*res = CPLRecode( src.toUtf8().constData(), CPL_ENC_UTF8, mName.constData() );
55
if
( !res )
56
{
57
QgsDebugError
(
"convertFromUnicode failed"
);
58
return
QByteArray();
59
}
60
61
const
QByteArray result = QByteArray( res );
62
CPLFree( res );
63
return
result;
64
}
65
66
// MY 5 YEAR OLD DAUGHTER WROTE THIS LINE, REMOVE AT YOUR OWN RISK!!!
67
// i don't want this to be here
68
69
QByteArray
QgsOgrProxyTextCodec::name
()
const
70
{
71
return
mName;
72
}
73
74
QList<QByteArray>
QgsOgrProxyTextCodec::aliases
()
const
75
{
76
return
QList<QByteArray>();
77
}
78
79
int
QgsOgrProxyTextCodec::mibEnum
()
const
80
{
81
// doesn't seem required in this case
82
return
0;
83
}
84
85
QStringList
QgsOgrProxyTextCodec::supportedCodecs
()
86
{
87
static
QStringList codecs;
88
static
std::once_flag initialized;
89
std::call_once( initialized, [&]() {
90
// there's likely others that are supported by GDAL, but we're primarily concerned here
91
// with codecs used by the shapefile driver, and which are no longer supported on the
92
// windows Qt builds (due to removal of ICU support in windows Qt builds)
93
// see https://github.com/qgis/QGIS/issues/36871
94
for
(
int
i = 437; i <= 950; ++i )
95
codecs << u
"CP%1"
_s.arg( i );
96
for
(
int
i = 1250; i <= 1258; ++i )
97
codecs << u
"CP%1"
_s.arg( i );
98
codecs << u
"CP1251"
_s;
99
} );
100
return
codecs;
101
}
QgsOgrProxyTextCodec::name
QByteArray name() const override
Definition
qgsogrproxytextcodec.cpp:69
QgsOgrProxyTextCodec::convertFromUnicode
QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const override
Definition
qgsogrproxytextcodec.cpp:48
QgsOgrProxyTextCodec::QgsOgrProxyTextCodec
QgsOgrProxyTextCodec(const QByteArray &name)
Constructor for QgsOgrProxyTextCodec, for the specified encoding name.
Definition
qgsogrproxytextcodec.cpp:27
QgsOgrProxyTextCodec::convertToUnicode
QString convertToUnicode(const char *in, int length, ConverterState *state) const override
Definition
qgsogrproxytextcodec.cpp:31
QgsOgrProxyTextCodec::mibEnum
int mibEnum() const override
Definition
qgsogrproxytextcodec.cpp:79
QgsOgrProxyTextCodec::aliases
QList< QByteArray > aliases() const override
Definition
qgsogrproxytextcodec.cpp:74
QgsOgrProxyTextCodec::supportedCodecs
static QStringList supportedCodecs()
Returns a list of supported text codecs.
Definition
qgsogrproxytextcodec.cpp:85
qgslogger.h
QgsDebugError
#define QgsDebugError(str)
Definition
qgslogger.h:71
qgsogrproxytextcodec.h
Generated on
for QGIS API Documentation by
1.17.0