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 ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Skip files with the extensions different to .aar to speed up the
|
// Skip files with the extensions different to .aar to speed up the
|
||||||
// scanning
|
// scanning
|
||||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".aar" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase(fileName, ".aar" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Got the file -- check if we need to rebuid the index
|
// 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 ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Skip files with the extensions different to .bgl to speed up the
|
// Skip files with the extensions different to .bgl to speed up the
|
||||||
// scanning
|
// scanning
|
||||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".bgl" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".bgl" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Got the file -- check if we need to rebuid the index
|
// 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 ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Only allow .index suffixes
|
// Only allow .index suffixes
|
||||||
|
|
||||||
if ( fileName.size() < 6 || strcasecmp( fileName.c_str() + ( fileName.size() - 6 ), ".index" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".index" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1713,10 +1713,8 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Try .dsl and .dsl.dz suffixes
|
// Try .dsl and .dsl.dz suffixes
|
||||||
|
|
||||||
bool uncompressedDsl =
|
bool uncompressedDsl = Utils::endsWithIgnoreCase( fileName, ".dsl" );
|
||||||
( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dsl" ) == 0 );
|
if ( !uncompressedDsl && !Utils::endsWithIgnoreCase( fileName, ".dsl.dz" ) )
|
||||||
if ( !uncompressedDsl
|
|
||||||
&& ( fileName.size() < 7 || strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".dsl.dz" ) != 0 ) )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Make sure it's not an abbreviation file
|
// 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 ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Try .gls and .gls.dz suffixes
|
// Try .gls and .gls.dz suffixes
|
||||||
|
|
||||||
if ( !( fileName.size() >= 4 && strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".gls" ) == 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".gls" ) && !Utils::endsWithIgnoreCase( fileName, ".gls.dz" ) )
|
||||||
&& !( fileName.size() >= 7 && strcasecmp( fileName.c_str() + ( fileName.size() - 7 ), ".gls.dz" ) == 0 ) )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
unsigned atLine = 0; // Indicates current line in .gls, for debug purposes
|
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 )
|
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 );
|
return string( str, 0, str.size() - 4 );
|
||||||
else
|
else
|
||||||
return str;
|
return str;
|
||||||
|
@ -494,15 +494,12 @@ void LsaDictionary::loadIcon() noexcept
|
||||||
vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & fileNames,
|
vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & fileNames,
|
||||||
string const & indicesDir,
|
string const & indicesDir,
|
||||||
Dictionary::Initializing & initializing )
|
Dictionary::Initializing & initializing )
|
||||||
|
|
||||||
{
|
{
|
||||||
vector< sptr< Dictionary::Class > > dictionaries;
|
vector< sptr< Dictionary::Class > > dictionaries;
|
||||||
|
|
||||||
for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i ) {
|
for ( vector< string >::const_iterator i = fileNames.begin(); i != fileNames.end(); ++i ) {
|
||||||
/// Only allow .dat and .lsa extensions to save scanning time
|
/// Only allow .dat and .lsa extensions to save scanning time
|
||||||
if ( i->size() < 4
|
if ( !Utils::endsWithIgnoreCase(i->c_str(),".dat") &&!Utils::endsWithIgnoreCase(i->c_str(),".lsa") )
|
||||||
|| ( strcasecmp( i->c_str() + ( i->size() - 4 ), ".dat" ) != 0
|
|
||||||
&& strcasecmp( i->c_str() + ( i->size() - 4 ), ".lsa" ) != 0 ) )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1272,7 +1272,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Skip files with the extensions different to .mdx to speed up the
|
// Skip files with the extensions different to .mdx to speed up the
|
||||||
// scanning
|
// scanning
|
||||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".mdx" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase(fileName,".mdx"))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
vector< string > dictFiles( 1, fileName );
|
vector< string > dictFiles( 1, fileName );
|
||||||
|
|
|
@ -661,7 +661,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Skip files with the extensions different to .dct to speed up the
|
// Skip files with the extensions different to .dct to speed up the
|
||||||
// scanning
|
// scanning
|
||||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".dct" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".dct" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// Got the file -- check if we need to rebuid the index
|
// 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;
|
vector< sptr< Dictionary::Class > > dictionaries;
|
||||||
|
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
if ( fileName.size() < 4 || strcasecmp( fileName.c_str() + ( fileName.size() - 4 ), ".ifo" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".ifo" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -1010,8 +1010,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
// Only allow .xdxf and .xdxf.dz suffixes
|
// Only allow .xdxf and .xdxf.dz suffixes
|
||||||
|
|
||||||
if ( ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".xdxf" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".xdxf" ) && !Utils::endsWithIgnoreCase( fileName, ".xdxf.dz" ) )
|
||||||
&& ( fileName.size() < 8 || strcasecmp( fileName.c_str() + ( fileName.size() - 8 ), ".xdxf.dz" ) != 0 ) )
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -383,7 +383,7 @@ vector< sptr< Dictionary::Class > > makeDictionaries( vector< string > const & f
|
||||||
|
|
||||||
for ( const auto & fileName : fileNames ) {
|
for ( const auto & fileName : fileNames ) {
|
||||||
/// Only allow .zips extension
|
/// Only allow .zips extension
|
||||||
if ( fileName.size() < 5 || strcasecmp( fileName.c_str() + ( fileName.size() - 5 ), ".zips" ) != 0 )
|
if ( !Utils::endsWithIgnoreCase( fileName, ".zips" ) )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue