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 "BlockFilter.h" 00012 00013 00014 BlockFilter::BlockFilter(const QString & name, MtpContext * ctxt) : Filter(name,ctxt) { 00015 dependency = 0; 00016 m_context = ctxt; 00017 } 00018 00019 00020 BlockFilter::~BlockFilter() {} 00021 00022 bool BlockFilter::applyTo(QString & msg, Position pos) { 00023 switch (pos) { 00024 case BEGIN: { 00025 MtpRegExp re(beg_reg); 00026 bool match = re.exactMatch(msg); 00027 00028 if (match) { 00029 setResult(applyProcessedRegexpToPattern(re,pattern)); 00030 finished = false; 00031 } 00032 00033 return match; 00034 } 00035 case IN: { 00036 MtpRegExp re("^(<.*>)?([^<>]+)(<.*>)?"); 00037 bool match = re.exactMatch(msg); 00038 00039 if (match) 00040 setResult(applyProcessedRegexpToPattern(re,pattern)); 00041 00042 MtpRegExp test(end_reg); 00043 bool match_test = test.exactMatch(msg); 00044 00045 if (match_test) 00046 finished = true; 00047 00048 return match; 00049 } 00050 } 00051 return false; 00052 } 00053 00054 void BlockFilter::setInputDependency(InputFilter * in) { 00055 dependency = in; 00056 } 00057 00058 void BlockFilter::setBeginRegExp(const QString& reg) { 00059 begin = reg; 00060 this->beg_reg = MtpRegExp(reg,m_context); 00061 } 00062 00063 void BlockFilter::setEndRegExp(const QString& reg) { 00064 end = reg; 00065 this->end_reg = MtpRegExp(reg,m_context); 00066 } 00067 00068 InputFilter * BlockFilter::getInputDependency() { 00069 return dependency; 00070 } 00071 00072 bool BlockFilter::isFinished() const { 00073 return finished; 00074 } 00075 00076 void BlockFilter::setResultPattern(const QString& pat) { 00077 this->pattern = pat; 00078 } 00079 00080 QString BlockFilter::getBeginRegExp() const { 00081 return begin; 00082 } 00083 00084 QString BlockFilter::getEndRegExp() const { 00085 return end; 00086 } 00087 00088 QString BlockFilter::getResultPattern() const { 00089 return pattern; 00090 }