diff options
author | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-12 18:09:55 +0000 |
---|---|---|
committer | tpearson <tpearson@283d02a7-25f6-0310-bc7c-ecb5cbfe19da> | 2010-02-12 18:09:55 +0000 |
commit | 630b7196d93786595546565329160ff26332704b (patch) | |
tree | 16f570c8f65cf789945d96ab7c4c7c9a46c10e2f /src/pattern.cpp | |
download | tdeio-locate-630b7196d93786595546565329160ff26332704b.tar.gz tdeio-locate-630b7196d93786595546565329160ff26332704b.zip |
Added KDE3 version of kio-locate
git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/applications/kio-locate@1089224 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'src/pattern.cpp')
-rw-r--r-- | src/pattern.cpp | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/src/pattern.cpp b/src/pattern.cpp new file mode 100644 index 0000000..14c74e3 --- /dev/null +++ b/src/pattern.cpp @@ -0,0 +1,124 @@ +/*************************************************************************** + * kio-locate: KDE I/O Slave for the locate command * + * * + * Copyright (C) 2005 by Tobi Vollebregt * + * [email protected] * + * * + * Thanks to Google's Summer Of Code Program! * + * * + * Copyright (C) 2004 by Armin Straub * + * [email protected] * + * * + * This program was initially written by Michael Schuerig. * + * Although I have completely rewritten it, most ideas are adopted * + * from his original work. * + * * + * Copyright (C) 2002 by Michael Schuerig * + * [email protected] * + * * + * * + * 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. * + ***************************************************************************/ + +#include <kdebug.h> + +#include "pattern.h" + + +LocateRegExp::LocateRegExp(const QString& pattern, bool ignoreCase) +{ + m_ignoreCase = ignoreCase; + setPattern(pattern); +} + + +LocateRegExp::LocateRegExp() +{ +} + + +LocateRegExp::~LocateRegExp() +{ +} + + +bool LocateRegExp::isMatching(const QString& file) const +{ + bool matching = m_regExp.search(file) >= 0; + if (m_negated) { + matching = !matching; + } + return matching; +} + + +int LocateRegExp::getMatchPosition() const +{ + // Why is QRegExp::pos() non const? + return const_cast<LocateRegExp*>(this)->m_regExp.pos(); +} + + +int LocateRegExp::getMatchedLength() const +{ + return m_regExp.matchedLength(); +} + + +void LocateRegExp::setPattern(const QString& pattern) +{ + m_negated = false; + m_pattern = pattern; + if ((m_pattern.length() > 0) && (m_pattern[0] == '!')) { + m_negated = true; + m_pattern = m_pattern.mid(1, m_pattern.length()-1); + } + m_regExp = QRegExp(m_pattern, !m_ignoreCase); +} + + +QString LocateRegExp::getPattern() const +{ + return m_pattern; +} + + +LocateRegExpList::~LocateRegExpList() +{ +} + + +LocateRegExpList& LocateRegExpList::operator = (const QStringList& list) +{ + clear(); + QStringList::ConstIterator it = list.begin(); + for (; it != list.end(); ++it) { + append(LocateRegExp((*it), (*it) == (*it).lower())); + } + return *this; +} + + +bool LocateRegExpList::isMatchingOne(const QString& file) const +{ + bool matches = false; + LocateRegExpList::ConstIterator it = begin(); + for (; !matches && (it != end()); ++it) { + matches = (*it).isMatching(file); + } + return matches; +} + + +bool LocateRegExpList::isMatchingAll(const QString& file) const +{ + bool matches = true; + LocateRegExpList::ConstIterator it = begin(); + for (; matches && (it != end()); ++it) { + matches = (*it).isMatching(file); + } + return matches; +} |