use char32_t as the inner string unit.

This commit is contained in:
xiaoyifang 2021-10-20 23:02:37 +08:00
parent 728a5b9651
commit 9857ed0559
5 changed files with 6 additions and 31 deletions

14
main.cc
View file

@ -44,23 +44,12 @@
#include "lionsupport.h" #include "lionsupport.h"
#endif #endif
#if ( QT_VERSION >= QT_VERSION_CHECK( 5, 0, 0 ) )
void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const QString &mess ) void gdMessageHandler( QtMsgType type, const QMessageLogContext &context, const QString &mess )
{ {
Q_UNUSED( context ); Q_UNUSED( context );
QString message( mess ); QString message( mess );
QByteArray msg = message.toUtf8().constData(); QByteArray msg = message.toUtf8().constData();
#else
void gdMessageHandler( QtMsgType type, const char *msg_ )
{
QString message = QString::fromUtf8( msg_ );
QByteArray msg = QByteArray::fromRawData( msg_, strlen( msg_ ) );
#endif
switch (type) { switch (type) {
case QtDebugMsg: case QtDebugMsg:
@ -94,15 +83,12 @@ void gdMessageHandler( QtMsgType type, const char *msg_ )
else else
fprintf(stderr, "Fatal: %s\n", msg.constData()); fprintf(stderr, "Fatal: %s\n", msg.constData());
abort(); abort();
#if QT_VERSION >= QT_VERSION_CHECK( 5, 5, 0 )
case QtInfoMsg: case QtInfoMsg:
if( logFilePtr && logFilePtr->isOpen() ) if( logFilePtr && logFilePtr->isOpen() )
message.insert( 0, "Info: " ); message.insert( 0, "Info: " );
else else
fprintf(stderr, "Info: %s\n", msg.constData()); fprintf(stderr, "Info: %s\n", msg.constData());
break; break;
#endif
} }
if( logFilePtr && logFilePtr->isOpen() ) if( logFilePtr && logFilePtr->isOpen() )

View file

@ -629,9 +629,7 @@ MainWindow::MainWindow( Config::Class & cfg_ ):
ui.tabWidget->setCornerWidget( &addTab, Qt::TopLeftCorner ); ui.tabWidget->setCornerWidget( &addTab, Qt::TopLeftCorner );
//ui.tabWidget->setCornerWidget( &closeTab, Qt::TopRightCorner ); //ui.tabWidget->setCornerWidget( &closeTab, Qt::TopRightCorner );
#if QT_VERSION >= 0x040500
ui.tabWidget->setMovable( true ); ui.tabWidget->setMovable( true );
#endif
#ifndef Q_OS_WIN32 #ifndef Q_OS_WIN32
ui.tabWidget->setDocumentMode( true ); ui.tabWidget->setDocumentMode( true );

View file

@ -3,12 +3,15 @@
#include "wstring.hh" #include "wstring.hh"
#include "iconv.hh" #include "iconv.hh"
#include <wchar.h> #include <wchar.h>
#include <QString>
namespace gd namespace gd
{ {
wstring __nativeToWs( wchar_t const * str ) wstring __nativeToWs( wchar_t const * str )
{ {
return Iconv::toWstring( "WCHAR_T", str, wcslen( str ) * sizeof( wchar_t ) ); QString qStr=QString::fromWCharArray(str);
return qStr.toStdU32String();
//return Iconv::toWstring( "WCHAR_T", str, wcslen( str ) * sizeof( wchar_t ) );
} }
} }

View file

@ -43,10 +43,9 @@
namespace gd namespace gd
{ {
#ifdef __WIN32
typedef char32_t wchar; typedef char32_t wchar;
typedef std::u32string wstring; typedef std::u32string wstring;
#ifdef __WIN32
// GD_NATIVE_TO_WS is used to convert L"" strings to a const pointer to // GD_NATIVE_TO_WS is used to convert L"" strings to a const pointer to
// wchar. // wchar.
@ -55,8 +54,6 @@ namespace gd
#else #else
typedef char32_t wchar;
typedef std::u32string wstring;
#define GD_NATIVE_TO_WS( str ) ( str ) #define GD_NATIVE_TO_WS( str ) ( str )
#endif #endif
} }

View file

@ -3,22 +3,13 @@
namespace gd namespace gd
{ {
#ifdef __WIN32
QString toQString( wstring const & in ) QString toQString( wstring const & in )
{ {
return QString::fromUcs4( in.c_str() ); return QString::fromUcs4( in.c_str() );
} }
#else
QString toQString( wstring const & in )
{
return QString::fromStdWString( in );
}
#endif
wstring toWString( QString const & in ) wstring toWString( QString const & in )
{ {
QVector< unsigned int > v = in.toUcs4(); QVector< unsigned int > v = in.toUcs4();