mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-30 17:24:08 +00:00
opt: refactor the compare logic
This commit is contained in:
parent
8313d93469
commit
4226abf593
|
@ -750,7 +750,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Skip files with the extensions different to .aar to speed up the
|
||||
// scanning
|
||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".aar" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase(fileName, ".aar" ) )
|
||||
continue;
|
||||
|
||||
// Got the file -- check if we need to rebuid the index
|
||||
|
|
|
@ -1017,7 +1017,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Skip files with the extensions different to .bgl to speed up the
|
||||
// scanning
|
||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".bgl" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".bgl" ) )
|
||||
continue;
|
||||
|
||||
// Got the file -- check if we need to rebuid the index
|
||||
|
|
|
@ -550,7 +550,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Only allow .index suffixes
|
||||
|
||||
if ( fileName.size() < 6 || strcasecmp( fileName.c_str() + ( fileName.size() - 6 ), ".index" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".index" ) )
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
|
@ -1713,10 +1713,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Try .dsl and .dsl.dz suffixes
|
||||
|
||||
bool uncompressedDsl =
|
||||
( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dsl" ) == 0 );
|
||||
if ( !uncompressedDsl
|
||||
&& ( fileName.size() < 7 || strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".dsl.dz" ) != 0 ) )
|
||||
bool uncompressedDsl = Utils::endsWithIgnoreCase( fileName, ".dsl" );
|
||||
if ( !uncompressedDsl && !Utils::endsWithIgnoreCase( fileName, ".dsl.dz" ) )
|
||||
continue;
|
||||
|
||||
// Make sure it's not an abbreviation file
|
||||
|
|
|
@ -1195,8 +1195,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Try .gls and .gls.dz suffixes
|
||||
|
||||
if ( !( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".gls" ) == 0 )
|
||||
&& !( fileName.size() >= 7 && strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".gls.dz" ) == 0 ) )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".gls" ) && !Utils::endsWithIgnoreCase( fileName, ".gls.dz" ) )
|
||||
continue;
|
||||
|
||||
unsigned atLine = 0; // Indicates current line in .gls, for debug purposes
|
||||
|
|
|
@ -75,7 +75,7 @@ bool indexIsOldOrBad( string const & indexFile )
|
|||
|
||||
string stripExtension( string const & str )
|
||||
{
|
||||
if ( str.size() > 3 && ( strcasecmp( str.c_str() + ( str.size() - 4 ), ".wav" ) == 0 ) )
|
||||
if ( Utils::endsWithIgnoreCase(str, ".wav" ) )
|
||||
return string( str, 0, str.size() - 4 );
|
||||
else
|
||||
return str;
|
||||
|
@ -494,15 +494,12 @@ void LsaDictionary::loadIcon() noexcept
|
|||
vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & fileNames,
|
||||
string const & indicesDir,
|
||||
Dictionary::Initializing & initializing )
|
||||
|
||||
{
|
||||
vector< sptr< Dictionary::Class > > dictionaries;
|
||||
|
||||
for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i ) {
|
||||
/// Only allow .dat and .lsa extensions to save scanning time
|
||||
if ( i->size() < 4
|
||||
|| ( strcasecmp( i->c_str() + ( i->size() - 4 ), ".dat" ) != 0
|
||||
&& strcasecmp( i->c_str() + ( i->size() - 4 ), ".lsa" ) != 0 ) )
|
||||
if ( !Utils::endsWithIgnoreCase(i->c_str(),".dat") &&!Utils::endsWithIgnoreCase(i->c_str(),".lsa") )
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
|
@ -1272,7 +1272,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Skip files with the extensions different to .mdx to speed up the
|
||||
// scanning
|
||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".mdx" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase(fileName,".mdx"))
|
||||
continue;
|
||||
|
||||
vector< string > dictFiles( 1, fileName );
|
||||
|
|
|
@ -661,7 +661,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Skip files with the extensions different to .dct to speed up the
|
||||
// scanning
|
||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dct" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".dct" ) )
|
||||
continue;
|
||||
|
||||
// Got the file -- check if we need to rebuid the index
|
||||
|
|
|
@ -1775,7 +1775,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
vector< sptr< Dictionary::Class > > dictionaries;
|
||||
|
||||
for ( const auto & fileName : fileNames ) {
|
||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".ifo" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".ifo" ) )
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
|
@ -1010,8 +1010,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
for ( const auto & fileName : fileNames ) {
|
||||
// Only allow .xdxf and .xdxf.dz suffixes
|
||||
|
||||
if ( ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".xdxf" ) != 0 )
|
||||
&& ( fileName.size() < 8 || strcasecmp( fileName.c_str() + ( fileName.size() - 8 ), ".xdxf.dz" ) != 0 ) )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".xdxf" ) && !Utils::endsWithIgnoreCase( fileName, ".xdxf.dz" ) )
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
|
@ -383,7 +383,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
|||
|
||||
for ( const auto & fileName : fileNames ) {
|
||||
/// Only allow .zips extension
|
||||
if ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".zips" ) != 0 )
|
||||
if ( !Utils::endsWithIgnoreCase( fileName, ".zips" ) )
|
||||
continue;
|
||||
|
||||
try {
|
||||
|
|
Loading…
Reference in a new issue