/***************************************************************** Copyright (c) 2006 Stephan Binner This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. ******************************************************************/ #include "query.h" #include Query::Query() { alternatives.setAutoDelete(true); } void Query::clear() { query_term = TQString::null; alternatives.clear(); } void Query::set(const TQString &term) { query_term = term; alternatives.clear(); current_alternative = new Alternative; current_part = TQString::null; within_quotes = false; exclude_part = false; for (uint index=0;indexexcludes+=current_part.lower(); else current_alternative->includes+=current_part.lower(); } within_quotes = false; exclude_part = false; current_part = TQString::null; } TQString Query::get() const { return query_term; } bool Query::matches(const TQString &term) { TQString lower_term = term.lower(); for (Alternative* alt=alternatives.first(); alt; alt=alternatives.next()) { if (!alt->includes.count()) continue; bool next_alternative = false; for ( TQStringList::ConstIterator it = alt->excludes.begin(); it != alt->excludes.end(); ++it ) { if ( lower_term.find(*it)!=-1 ) { next_alternative = true; continue; } } if (next_alternative) continue; for ( TQStringList::ConstIterator it = alt->includes.begin(); it != alt->includes.end(); ++it ) { if ( lower_term.find(*it)==-1 ) { next_alternative = true; continue; } } if (next_alternative) continue; //kdDebug() << "Found hit in '" << term << "'" << endl; return true; } return false; }