mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 19:24:08 +00:00
Fix unexpected result using QString::toStdWString() (fix #107 again, QTBUG-25536)
* QString::toStdWString() and QString::toUCS4() will have wrong size when QString instances contain non-BMP characters. Close #320
This commit is contained in:
parent
427c0df90e
commit
07113d0bf6
2
mdx.cc
2
mdx.cc
|
@ -56,7 +56,7 @@ using namespace Mdict;
|
|||
enum
|
||||
{
|
||||
kSignature = 0x4349444d, // MDIC
|
||||
kCurrentFormatVersion = 8 + BtreeIndexing::FormatVersion
|
||||
kCurrentFormatVersion = 8 + BtreeIndexing::FormatVersion + Folding::Version
|
||||
};
|
||||
|
||||
DEF_EX( exCorruptDictionary, "dictionary file was tampered or corrupted", std::exception )
|
||||
|
|
|
@ -10,19 +10,6 @@ namespace gd
|
|||
return QString::fromUcs4( in.c_str() );
|
||||
}
|
||||
|
||||
wstring toWString( QString const & in )
|
||||
{
|
||||
QVector< unsigned int > v = in.toUcs4();
|
||||
|
||||
// Fix for CJK Extension B characters
|
||||
int n = v.size();
|
||||
while( n > 0 && v[ n - 1 ] == 0 ) n--;
|
||||
if( n != v.size() )
|
||||
v.resize( n );
|
||||
|
||||
return wstring( v.constData(), v.size() );
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
QString toQString( wstring const & in )
|
||||
|
@ -30,9 +17,20 @@ namespace gd
|
|||
return QString::fromStdWString( in );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
wstring toWString( QString const & in )
|
||||
{
|
||||
return in.toStdWString();
|
||||
QVector< unsigned int > v = in.toUcs4();
|
||||
|
||||
// Fix for QString instance which contains non-BMP characters
|
||||
// Qt will created unexpected null characters may confuse btree indexer.
|
||||
// Related: https://bugreports.qt-project.org/browse/QTBUG-25536
|
||||
int n = v.size();
|
||||
while ( n > 0 && v[ n - 1 ] == 0 ) n--;
|
||||
if ( n != v.size() )
|
||||
v.resize( n );
|
||||
|
||||
return wstring( ( const wchar * ) v.constData(), v.size() );
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue