QGIS API Documentation 3.99.0-Master (d270888f95f)
Loading...
Searching...
No Matches
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
17
18#include <cpl_string.h>
19#include <mutex>
20
21#include "qgslogger.h"
22
23#include <QString>
24
25using namespace Qt::StringLiterals;
26
28 : mName( name )
29{
30
31}
32
33QString QgsOgrProxyTextCodec::convertToUnicode( const char *chars, int, ConverterState * ) const
34{
35 if ( !chars )
36 return QString();
37
38 char *res = CPLRecode( chars, mName.constData(), CPL_ENC_UTF8 );
39 if ( !res )
40 {
41 QgsDebugError( "convertToUnicode failed" );
42 return QString();
43 }
44
45 const QString result = QString::fromUtf8( res );
46 CPLFree( res );
47 return result;
48}
49
50QByteArray QgsOgrProxyTextCodec::convertFromUnicode( const QChar *unicode, int length, ConverterState * ) const
51{
52 if ( !unicode )
53 return QByteArray();
54
55 const QString src = QString( unicode, length );
56 char *res = CPLRecode( src.toUtf8().constData(), CPL_ENC_UTF8, mName.constData() );
57 if ( !res )
58 {
59 QgsDebugError( "convertFromUnicode failed" );
60 return QByteArray();
61 }
62
63 const QByteArray result = QByteArray( res );
64 CPLFree( res );
65 return result;
66}
67
68// MY 5 YEAR OLD DAUGHTER WROTE THIS LINE, REMOVE AT YOUR OWN RISK!!!
69// i don't want this to be here
70
72{
73 return mName;
74}
75
76QList<QByteArray> QgsOgrProxyTextCodec::aliases() const
77{
78 return QList<QByteArray>();
79}
80
82{
83 // doesn't seem required in this case
84 return 0;
85}
86
88{
89 static QStringList codecs;
90 static std::once_flag initialized;
91 std::call_once( initialized, [&]( )
92 {
93 // there's likely others that are supported by GDAL, but we're primarily concerned here
94 // with codecs used by the shapefile driver, and which are no longer supported on the
95 // windows Qt builds (due to removal of ICU support in windows Qt builds)
96 // see https://github.com/qgis/QGIS/issues/36871
97 for ( int i = 437; i <= 950; ++i )
98 codecs << u"CP%1"_s.arg( i );
99 for ( int i = 1250; i <= 1258; ++i )
100 codecs << u"CP%1"_s.arg( i );
101 codecs << u"CP1251"_s;
102 } );
103 return codecs;
104}
QByteArray name() const override
QByteArray convertFromUnicode(const QChar *in, int length, ConverterState *state) const override
QgsOgrProxyTextCodec(const QByteArray &name)
Constructor for QgsOgrProxyTextCodec, for the specified encoding name.
QString convertToUnicode(const char *in, int length, ConverterState *state) const override
int mibEnum() const override
QList< QByteArray > aliases() const override
static QStringList supportedCodecs()
Returns a list of supported text codecs.
#define QgsDebugError(str)
Definition qgslogger.h:59