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