Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

MtpRegExp.cpp

Go to the documentation of this file.
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 "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 }

Generated on Sat May 10 15:09:27 2003 for qnet by doxygen1.3