00001 /*************************************************************************** 00002 * Copyright (C) 2002 by Yann Hodique * 00003 * Yann.Hodique@lifl.fr * 00004 * * 00005 * This program is free software; you can redistribute it and/or modify * 00006 * it under the terms of the GNU General Public License as published by * 00007 * the Free Software Foundation; either version 2 of the License, or * 00008 * (at your option) any later version. * 00009 ***************************************************************************/ 00010 00011 #include "ItemFilter.h" 00012 #include <iostream> 00013 #include <qregexp.h> 00014 00015 ItemFilter::ItemFilter(const QString & name, MtpContext * ctxt) : Filter(name,ctxt) { 00016 setPolicy(Filter::Final); 00017 m_context = ctxt; 00018 } 00019 00020 00021 ItemFilter::~ItemFilter() {} 00022 00023 bool ItemFilter::applyTo(QString & msg) { 00024 /*MtpRegExp re(reg); 00025 bool match = re.exactMatch(msg); 00026 00027 if (match) setResult(applyProcessedRegexpToPattern(re,pattern)); 00028 00029 return match; 00030 */ 00031 00032 QRegExp rx(reg_exp); 00033 QString res(""); 00034 int pos = 0; 00035 int tmp; 00036 00037 00038 while ( ((tmp = rx.search(msg, pos)) != -1) && rx.matchedLength() ) { 00039 //std::cout << "tmp = " << tmp << std::endl; 00040 //std::cout << "length = " << rx.matchedLength() << std::endl; 00041 res += msg.right(msg.length()-pos).left(tmp-pos); 00042 00043 QString ok(msg.right(msg.length()-tmp).left(rx.matchedLength())); 00044 00045 MtpRegExp re(reg); 00046 if (re.exactMatch(ok)) { 00047 res += applyProcessedRegexpToPattern(re,pattern); 00048 } 00049 pos = tmp; 00050 pos += rx.matchedLength(); 00051 } 00052 res += msg.right(msg.length()-pos); 00053 setResult(res); 00054 00055 return pos; 00056 00057 } 00058 00059 void ItemFilter::setRegExp(const QString& reg) { 00060 this->reg = MtpRegExp(reg, m_context); 00061 reg_exp = reg; 00062 } 00063 00064 void ItemFilter::setResultPattern(const QString& pat) { 00065 this->pattern = pat; 00066 } 00067 00068 QString ItemFilter::getRegExp() const { 00069 return reg_exp; 00070 } 00071 00072 QString ItemFilter::getResultPattern() const { 00073 return pattern; 00074 }