00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include "MtpRegExp.h"
00012 #include <iostream>
00013
00014
00015 MtpRegExp::MtpRegExp(const QString & pat, MtpContext * ctxt) {
00016 pattern = pat;
00017 m_context = ctxt;
00018 }
00019
00020 MtpRegExp::~MtpRegExp() {}
00021
00022 bool MtpRegExp::exactMatch(const QString & str) {
00023
00024 QString res(pattern);
00025 if (m_context) {
00026 QRegExp rx( "\\\\(\\w+)\\\\" );
00027 QStringList list;
00028
00029 int pos = 0;
00030 while ( pos >= 0 ) {
00031 pos = rx.search( pattern, pos );
00032 if ( pos > -1 ) {
00033 list += rx.cap( 1 );
00034 pos += rx.matchedLength();
00035 }
00036 }
00037 for (QStringList::Iterator it = list.begin(); it != list.end(); ++it) {
00038 QString value;
00039 if ((value = m_context->getValue(*it)) != QString::null)
00040 res = res.replace(QRegExp("\\\\" + *it + "\\\\"),value);
00041 else
00042 return false;
00043 }
00044 }
00045
00046 reg = QRegExp(res);
00047 return reg.exactMatch(str);
00048 }
00049
00050 QString MtpRegExp::cap(int i) {
00051 return reg.cap(i);
00052 }
00053
00054 int MtpRegExp::search(const QString & msg, int & n) const {
00055 return reg.search(msg,n);
00056 }
00057
00058 int MtpRegExp::matchedLength() const {
00059 return reg.matchedLength();
00060 }