mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
clean: rename LangCoder::findIdsForFilename/findIdsForName/exists
This commit is contained in:
parent
6a91c6bde3
commit
3a0880fa81
|
@ -695,12 +695,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
idxHeader.signature = Signature;
|
||||
idxHeader.formatVersion = CurrentFormatVersion;
|
||||
|
||||
// read languages
|
||||
QPair< quint32, quint32 > langs = LangCoder::findIdsForFilename( QString::fromStdString( dictFiles[ 0 ] ) );
|
||||
// read languages from dictioanry file name
|
||||
auto langs = LangCoder::findLangIdPairFromPath( dictFiles[ 0 ] );
|
||||
|
||||
// if no languages found, try dictionary's name
|
||||
if ( langs.first == 0 || langs.second == 0 ) {
|
||||
langs = LangCoder::findIdsForFilename( QString::fromStdString( nameFromFileName( dictFiles[ 0 ] ) ) );
|
||||
langs = LangCoder::findLangIdPairFromStr( QString::fromStdString( dictionaryName ) );
|
||||
}
|
||||
|
||||
idxHeader.langFrom = langs.first;
|
||||
|
|
|
@ -1367,11 +1367,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
idxHeader.langTo = LangCoder::findIdForLanguage( scanner.getLangTo() );
|
||||
if ( idxHeader.langFrom == 0 && idxHeader.langTo == 0 ) {
|
||||
// if no languages found, try dictionary's file name
|
||||
QPair< quint32, quint32 > langs = LangCoder::findIdsForFilename( QString::fromStdString( dictFiles[ 0 ] ) );
|
||||
auto langs = LangCoder::findLangIdPairFromPath( dictFiles[ 0 ] );
|
||||
|
||||
// if no languages found, try dictionary's name
|
||||
if ( langs.first == 0 || langs.second == 0 ) {
|
||||
langs = LangCoder::findIdsForFilename( QString::fromStdString( dictionaryName ) );
|
||||
langs = LangCoder::findLangIdPairFromStr( QString::fromStdString( dictionaryName ) );
|
||||
}
|
||||
idxHeader.langFrom = langs.first;
|
||||
idxHeader.langTo = langs.second;
|
||||
|
|
|
@ -1422,12 +1422,12 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
}
|
||||
}
|
||||
|
||||
// read languages
|
||||
QPair< quint32, quint32 > langs = LangCoder::findIdsForFilename( QString::fromStdString( fileName ) );
|
||||
// read languages from dictioanry's file name
|
||||
auto langs = LangCoder::findLangIdPairFromPath( fileName );
|
||||
|
||||
// if no languages found, try dictionary's name
|
||||
// if no languages found, try dictionary name
|
||||
if ( langs.first == 0 || langs.second == 0 ) {
|
||||
langs = LangCoder::findIdsForFilename( parser.title() );
|
||||
langs = LangCoder::findLangIdPairFromStr( parser.title() );
|
||||
}
|
||||
|
||||
idxHeader.langFrom = langs.first;
|
||||
|
|
|
@ -1318,7 +1318,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
idxHeader.articleCount = articleCount;
|
||||
idxHeader.wordCount = wordCount;
|
||||
|
||||
QPair< quint32, quint32 > langs = LangCoder::findIdsForFilename( QString::fromStdString( dictFiles[ 0 ] ) );
|
||||
auto langs = LangCoder::findLangIdPairFromPath( dictFiles[ 0 ] );
|
||||
|
||||
idxHeader.langFrom = langs.first;
|
||||
idxHeader.langTo = langs.second;
|
||||
|
|
|
@ -1903,12 +1903,11 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
idxHeader.bookNameSize = ifo.bookname.size();
|
||||
idxHeader.sameTypeSequenceSize = ifo.sametypesequence.size();
|
||||
|
||||
// read languages
|
||||
QPair< quint32, quint32 > langs = LangCoder::findIdsForFilename( QString::fromStdString( dictFileName ) );
|
||||
|
||||
// read languages from dictioanry file name
|
||||
auto langs = LangCoder::findLangIdPairFromStr( QString::fromStdString( dictFileName ) );
|
||||
// if no languages found, try dictionary's name
|
||||
if ( langs.first == 0 || langs.second == 0 ) {
|
||||
langs = LangCoder::findIdsForFilename( QString::fromStdString( ifo.bookname ) );
|
||||
langs = LangCoder::findLangIdPairFromStr( QString::fromStdString( ifo.bookname ) );
|
||||
}
|
||||
|
||||
idxHeader.langFrom = langs.first;
|
||||
|
|
|
@ -208,19 +208,19 @@ QMap< QString, GDLangCode > LangCoder::LANG_CODE_MAP = {
|
|||
|
||||
QString LangCoder::decode( quint32 _code )
|
||||
{
|
||||
if ( auto code = intToCode2( _code ); exists( code ) )
|
||||
if ( auto code = intToCode2( _code ); code2Exists( code ) )
|
||||
return QString::fromStdString( LANG_CODE_MAP[ code ].lang );
|
||||
|
||||
return {};
|
||||
}
|
||||
bool LangCoder::exists( const QString & _code )
|
||||
bool LangCoder::code2Exists( const QString & _code )
|
||||
{
|
||||
return LANG_CODE_MAP.contains( _code );
|
||||
}
|
||||
|
||||
QIcon LangCoder::icon( quint32 _code )
|
||||
{
|
||||
if ( auto code = intToCode2( _code ); exists( code ) ) {
|
||||
if ( auto code = intToCode2( _code ); code2Exists( code ) ) {
|
||||
const GDLangCode & lc = LANG_CODE_MAP[ code ];
|
||||
return QIcon( ":/flags/" + QString( lc.code ) + ".png" );
|
||||
}
|
||||
|
@ -285,7 +285,7 @@ quint32 LangCoder::guessId( const QString & lang )
|
|||
return code2toInt( lstr.left( 2 ).toLatin1().data() );
|
||||
}
|
||||
|
||||
QPair< quint32, quint32 > LangCoder::findIdsForName( QString const & name )
|
||||
std::pair< quint32, quint32 > LangCoder::findLangIdPairFromStr( QString const & name )
|
||||
{
|
||||
QString nameFolded = "|" + name.toCaseFolded() + "|";
|
||||
QRegExp reg( "[^a-z]([a-z]{2,3})-([a-z]{2,3})[^a-z]" );
|
||||
|
@ -304,14 +304,14 @@ QPair< quint32, quint32 > LangCoder::findIdsForName( QString const & name )
|
|||
return QPair< quint32, quint32 >( 0, 0 );
|
||||
}
|
||||
|
||||
QPair< quint32, quint32 > LangCoder::findIdsForFilename( QString const & name )
|
||||
static std::pair< quint32, quint32 > findLangIdPairFromPath( std::string const & p )
|
||||
{
|
||||
return findIdsForName( QFileInfo( name ).fileName() );
|
||||
return LangCoder::findLangIdPairFromStr( QFileInfo( QString::fromStdString( p ) ).fileName() );
|
||||
}
|
||||
|
||||
bool LangCoder::isLanguageRTL( quint32 _code )
|
||||
{
|
||||
if ( auto code = intToCode2( _code ); exists( code ) ) {
|
||||
if ( auto code = intToCode2( _code ); code2Exists( code ) ) {
|
||||
GDLangCode lc = LANG_CODE_MAP[ code ];
|
||||
if ( lc.isRTL < 0 ) {
|
||||
lc.isRTL = static_cast< int >( QLocale( lc.code ).textDirection() == Qt::RightToLeft );
|
||||
|
|
|
@ -39,8 +39,9 @@ public:
|
|||
|
||||
static quint32 findIdForLanguageCode3( std::string const & );
|
||||
|
||||
static QPair< quint32, quint32 > findIdsForName( QString const & );
|
||||
static QPair< quint32, quint32 > findIdsForFilename( QString const & );
|
||||
/// find id pairs like en-zh in dictioanry name
|
||||
static std::pair< quint32, quint32 > findLangIdPairFromStr( QString const & );
|
||||
static std::pair< quint32, quint32 > findLangIdPairFromPath( std::string const & );
|
||||
|
||||
static quint32 guessId( const QString & lang );
|
||||
|
||||
|
@ -54,7 +55,7 @@ public:
|
|||
|
||||
private:
|
||||
static QMap< QString, GDLangCode > LANG_CODE_MAP;
|
||||
static bool exists( const QString & _code );
|
||||
static bool code2Exists( const QString & _code );
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
@ -660,7 +660,8 @@ void DictGroupsWidget::addAutoGroups()
|
|||
if ( idFrom == 0 ) {
|
||||
// Attempt to find language pair in dictionary name
|
||||
|
||||
const QPair< quint32, quint32 > ids = LangCoder::findIdsForName( QString::fromUtf8( dict->getName().c_str() ) );
|
||||
const QPair< quint32, quint32 > ids =
|
||||
LangCoder::findLangIdPairFromStr( QString::fromUtf8( dict->getName().c_str() ) );
|
||||
idFrom = ids.first;
|
||||
idTo = ids.second;
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ bool dictLessThan( sptr< Dictionary::Class > const & dict1, sptr< Dictionary::Cl
|
|||
int idFrom1 = dict1->getLangFrom();
|
||||
int idTo1 = dict1->getLangTo();
|
||||
if ( idFrom1 == 0 ) {
|
||||
QPair< quint32, quint32 > ids = LangCoder::findIdsForName( QString::fromUtf8( dict1->getName().c_str() ) );
|
||||
QPair< quint32, quint32 > ids = LangCoder::findLangIdPairFromStr( QString::fromUtf8( dict1->getName().c_str() ) );
|
||||
idFrom1 = ids.first;
|
||||
idTo1 = ids.second;
|
||||
}
|
||||
|
@ -41,7 +41,7 @@ bool dictLessThan( sptr< Dictionary::Class > const & dict1, sptr< Dictionary::Cl
|
|||
int idFrom2 = dict2->getLangFrom();
|
||||
int idTo2 = dict2->getLangTo();
|
||||
if ( idFrom2 == 0 ) {
|
||||
QPair< quint32, quint32 > ids = LangCoder::findIdsForName( QString::fromUtf8( dict2->getName().c_str() ) );
|
||||
QPair< quint32, quint32 > ids = LangCoder::findLangIdPairFromStr( QString::fromUtf8( dict2->getName().c_str() ) );
|
||||
idFrom2 = ids.first;
|
||||
idTo2 = ids.second;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue