@@ -419,124 +419,60 @@ void SearchEngine::Search()
419419
420420 bool any_found = 1 ;
421421 bool found = 1 ;
422-
423- LocaleStringComparison cmp (std::locale (), Config.ignore_leading_the );
424- for (auto it = list.begin (); it != list.end (); ++it)
422+ boost::regex rx[11 ];
423+ if (SearchMode != &SearchModes[2 ]) // match to pattern
425424 {
426- if (SearchMode != &SearchModes[ 2 ]) // match to pattern
425+ for ( int i = 0 ; i < 11 ; ++i)
427426 {
428- boost::regex rx;
429- if (!itsConstraints[0 ].empty ())
430- {
431- try
432- {
433- rx.assign (itsConstraints[0 ], Config.regex_type );
434- any_found =
435- boost::regex_search (it->getArtist (), rx)
436- || boost::regex_search (it->getAlbumArtist (), rx)
437- || boost::regex_search (it->getTitle (), rx)
438- || boost::regex_search (it->getAlbum (), rx)
439- || boost::regex_search (it->getName (), rx)
440- || boost::regex_search (it->getComposer (), rx)
441- || boost::regex_search (it->getPerformer (), rx)
442- || boost::regex_search (it->getGenre (), rx)
443- || boost::regex_search (it->getDate (), rx)
444- || boost::regex_search (it->getComment (), rx);
445- }
446- catch (boost::bad_expression &) { }
447- }
448-
449- if (found && !itsConstraints[1 ].empty ())
450- {
451- try
452- {
453- rx.assign (itsConstraints[1 ], Config.regex_type );
454- found = boost::regex_search (it->getArtist (), rx);
455- }
456- catch (boost::bad_expression &) { }
457- }
458- if (found && !itsConstraints[2 ].empty ())
459- {
460- try
461- {
462- rx.assign (itsConstraints[2 ], Config.regex_type );
463- found = boost::regex_search (it->getAlbumArtist (), rx);
464- }
465- catch (boost::bad_expression &) { }
466- }
467- if (found && !itsConstraints[3 ].empty ())
468- {
469- try
470- {
471- rx.assign (itsConstraints[3 ], Config.regex_type );
472- found = boost::regex_search (it->getTitle (), rx);
473- }
474- catch (boost::bad_expression &) { }
475- }
476- if (found && !itsConstraints[4 ].empty ())
477- {
478- try
479- {
480- rx.assign (itsConstraints[4 ], Config.regex_type );
481- found = boost::regex_search (it->getAlbum (), rx);
482- }
483- catch (boost::bad_expression &) { }
484- }
485- if (found && !itsConstraints[5 ].empty ())
486- {
487- try
488- {
489- rx.assign (itsConstraints[5 ], Config.regex_type );
490- found = boost::regex_search (it->getName (), rx);
491- }
492- catch (boost::bad_expression &) { }
493- }
494- if (found && !itsConstraints[6 ].empty ())
495- {
496- try
497- {
498- rx.assign (itsConstraints[6 ], Config.regex_type );
499- found = boost::regex_search (it->getComposer (), rx);
500- }
501- catch (boost::bad_expression &) { }
502- }
503- if (found && !itsConstraints[7 ].empty ())
504- {
505- try
506- {
507- rx.assign (itsConstraints[7 ], Config.regex_type );
508- found = boost::regex_search (it->getPerformer (), rx);
509- }
510- catch (boost::bad_expression &) { }
511- }
512- if (found && itsConstraints[8 ].empty ())
513- {
514- try
515- {
516- rx.assign (itsConstraints[8 ], Config.regex_type );
517- found = boost::regex_search (it->getGenre (), rx);
518- }
519- catch (boost::bad_expression &) { }
520- }
521- if (found && !itsConstraints[9 ].empty ())
427+ if (!itsConstraints[i].empty ())
522428 {
523429 try
524430 {
525- rx.assign (itsConstraints[9 ], Config.regex_type );
526- found = boost::regex_search (it->getDate (), rx);
527- }
528- catch (boost::bad_expression &) { }
529- }
530- if (found && !itsConstraints[10 ].empty ())
531- {
532- try
533- {
534- rx.assign (itsConstraints[10 ], Config.regex_type );
535- found = boost::regex_search (it->getComment (), rx);
431+ rx[i].assign (itsConstraints[i], Config.regex_type );
536432 }
537433 catch (boost::bad_expression &) { }
538434 }
539435 }
436+ }
437+
438+ LocaleStringComparison cmp (std::locale (), Config.ignore_leading_the );
439+ for (auto it = list.begin (); it != list.end (); ++it)
440+ {
441+ if (SearchMode != &SearchModes[2 ]) // match to pattern
442+ {
443+ if (!rx[0 ].empty ())
444+ any_found =
445+ boost::regex_search (it->getArtist (), rx[0 ])
446+ || boost::regex_search (it->getAlbumArtist (), rx[0 ])
447+ || boost::regex_search (it->getTitle (), rx[0 ])
448+ || boost::regex_search (it->getAlbum (), rx[0 ])
449+ || boost::regex_search (it->getName (), rx[0 ])
450+ || boost::regex_search (it->getComposer (), rx[0 ])
451+ || boost::regex_search (it->getPerformer (), rx[0 ])
452+ || boost::regex_search (it->getGenre (), rx[0 ])
453+ || boost::regex_search (it->getDate (), rx[0 ])
454+ || boost::regex_search (it->getComment (), rx[0 ]);
455+ if (found && !rx[1 ].empty ())
456+ found = boost::regex_search (it->getArtist (), rx[1 ]);
457+ if (found && !rx[2 ].empty ())
458+ found = boost::regex_search (it->getAlbumArtist (), rx[2 ]);
459+ if (found && !rx[3 ].empty ())
460+ found = boost::regex_search (it->getTitle (), rx[3 ]);
461+ if (found && !rx[4 ].empty ())
462+ found = boost::regex_search (it->getAlbum (), rx[4 ]);
463+ if (found && !rx[5 ].empty ())
464+ found = boost::regex_search (it->getName (), rx[5 ]);
465+ if (found && !rx[6 ].empty ())
466+ found = boost::regex_search (it->getComposer (), rx[6 ]);
467+ if (found && !rx[7 ].empty ())
468+ found = boost::regex_search (it->getPerformer (), rx[7 ]);
469+ if (found && !rx[8 ].empty ())
470+ found = boost::regex_search (it->getGenre (), rx[8 ]);
471+ if (found && !rx[9 ].empty ())
472+ found = boost::regex_search (it->getDate (), rx[9 ]);
473+ if (found && !rx[10 ].empty ())
474+ found = boost::regex_search (it->getComment (), rx[10 ]);
475+ }
540476 else // match only if values are equal
541477 {
542478 if (!itsConstraints[0 ].empty ())
0 commit comments