mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-12-17 23:04:06 +00:00
fix: dsl ann file codec detection
This commit is contained in:
parent
0f3336977f
commit
3f49d92011
|
@ -48,7 +48,7 @@ QString unescapeAmps( QString const & str )
|
|||
return result;
|
||||
}
|
||||
|
||||
QTextCodec::Encoding detectEncoding( QByteArray & ba, char16_t expectedFirstCharacter = 0 )
|
||||
QTextCodec::Encoding detectCodec( QByteArray & ba, char16_t expectedFirstCharacter = 0 )
|
||||
{
|
||||
QStringConverter::Encoding detectedEncoding = QStringConverter::encodingForData( data, expectedFirstCharacter );
|
||||
// mapping the encoding
|
||||
|
@ -58,6 +58,17 @@ QTextCodec::Encoding detectEncoding( QByteArray & ba, char16_t expectedFirstChar
|
|||
// default utf8
|
||||
return QTextCodec::Utf8;
|
||||
}
|
||||
|
||||
QStringConverter::Encoding detectEncoding( QByteArray & ba, char16_t expectedFirstCharacter = 0 )
|
||||
{
|
||||
QStringConverter::Encoding detectedEncoding = QStringConverter::encodingForData( data, expectedFirstCharacter );
|
||||
// mapping the encoding
|
||||
if ( detectedEncoding.has_value() ) {
|
||||
return detectedEncoding.value();
|
||||
}
|
||||
// default utf8
|
||||
return QStringConverter::Utf8;
|
||||
}
|
||||
} // namespace Utils
|
||||
|
||||
QString Utils::Path::combine( const QString & path1, const QString & path2 )
|
||||
|
|
|
@ -371,6 +371,7 @@ const QMap< QStringConverter::Encoding, QTextCodec::Encoding > encodingMap = {
|
|||
};
|
||||
}
|
||||
|
||||
QTextCodec::Encoding detectEncoding( QByteArray & ba, char16_t expectedFirstCharacter = 0 );
|
||||
QTextCodec::Encoding detectCodec( QByteArray & ba, char16_t expectedFirstCharacter = 0 );
|
||||
QStringConverter::Encoding detectEncoding( QByteArray & ba, char16_t expectedFirstCharacter = 0 );
|
||||
|
||||
} // namespace Utils
|
||||
|
|
|
@ -1042,8 +1042,8 @@ QString const & DslDictionary::getDescription()
|
|||
QString data, str;
|
||||
|
||||
str = annStream.readLine();
|
||||
auto codec = Utils::detectEncoding( str );
|
||||
annStream.setCodec( codec );
|
||||
auto encoding = Utils::detectEncoding( str );
|
||||
annStream.setEncoding( encoding );
|
||||
|
||||
if ( str.left( 10 ).compare( "#LANGUAGE " ) != 0 ) {
|
||||
annStream.seek( 0 );
|
||||
|
|
|
@ -873,7 +873,7 @@ DslScanner::DslScanner( string const & fileName ):
|
|||
|
||||
// Note that .dsl format always starts with "#NAME"
|
||||
|
||||
codec = Utils::detectEncoding( { firstBytes, firstBytesSize }, '#' );
|
||||
codec = Utils::detectCodec( { firstBytes, firstBytesSize }, '#' );
|
||||
|
||||
qDebug() << "DSL encoding ->" << codec->name();
|
||||
|
||||
|
|
Loading…
Reference in a new issue