diff --git a/src/dict/aard.cc b/src/dict/aard.cc index 9e3ea1a0..77df1e3a 100644 --- a/src/dict/aard.cc +++ b/src/dict/aard.cc @@ -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 diff --git a/src/dict/bgl.cc b/src/dict/bgl.cc index b31af472..6f697dca 100644 --- a/src/dict/bgl.cc +++ b/src/dict/bgl.cc @@ -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 diff --git a/src/dict/dictdfiles.cc b/src/dict/dictdfiles.cc index a21fb234..c2ef09e1 100644 --- a/src/dict/dictdfiles.cc +++ b/src/dict/dictdfiles.cc @@ -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 { diff --git a/src/dict/dsl.cc b/src/dict/dsl.cc index cd5061b2..6a214d73 100644 --- a/src/dict/dsl.cc +++ b/src/dict/dsl.cc @@ -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 diff --git a/src/dict/gls.cc b/src/dict/gls.cc index 1a2650bb..739296cd 100644 --- a/src/dict/gls.cc +++ b/src/dict/gls.cc @@ -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 diff --git a/src/dict/lsa.cc b/src/dict/lsa.cc index 942a7713..a17f6187 100644 --- a/src/dict/lsa.cc +++ b/src/dict/lsa.cc @@ -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 { diff --git a/src/dict/mdx.cc b/src/dict/mdx.cc index 78ff80cd..6ab44439 100644 --- a/src/dict/mdx.cc +++ b/src/dict/mdx.cc @@ -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 ); diff --git a/src/dict/sdict.cc b/src/dict/sdict.cc index a8c4ff53..589ead36 100644 --- a/src/dict/sdict.cc +++ b/src/dict/sdict.cc @@ -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 diff --git a/src/dict/stardict.cc b/src/dict/stardict.cc index e4e81217..a34ae5ab 100644 --- a/src/dict/stardict.cc +++ b/src/dict/stardict.cc @@ -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 { diff --git a/src/dict/xdxf.cc b/src/dict/xdxf.cc index 7498c58a..bb7e40f7 100644 --- a/src/dict/xdxf.cc +++ b/src/dict/xdxf.cc @@ -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 { diff --git a/src/dict/zipsounds.cc b/src/dict/zipsounds.cc index a4c4bbc6..9b16c53d 100644 --- a/src/dict/zipsounds.cc +++ b/src/dict/zipsounds.cc @@ -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 {