blob: 6ca38415ee3f505077f30c6f829feb0c9952b84e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
|
/***************************************************************************
* tdeio-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 TQString& pattern, bool ignoreCase)
{
m_ignoreCase = ignoreCase;
setPattern(pattern);
}
LocateRegExp::LocateRegExp()
{
}
LocateRegExp::~LocateRegExp()
{
}
bool LocateRegExp::isMatching(const TQString& file) const
{
bool matching = m_regExp.search(file) >= 0;
if (m_negated) {
matching = !matching;
}
return matching;
}
int LocateRegExp::getMatchPosition() const
{
// Why is TQRegExp::pos() non const?
return const_cast<LocateRegExp*>(this)->m_regExp.pos();
}
int LocateRegExp::getMatchedLength() const
{
return m_regExp.matchedLength();
}
void LocateRegExp::setPattern(const TQString& 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 = TQRegExp(m_pattern, !m_ignoreCase);
}
TQString LocateRegExp::getPattern() const
{
return m_pattern;
}
LocateRegExpList::~LocateRegExpList()
{
}
LocateRegExpList& LocateRegExpList::operator = (const TQStringList& list)
{
clear();
TQStringList::ConstIterator it = list.begin();
for (; it != list.end(); ++it) {
append(LocateRegExp((*it), (*it) == (*it).lower()));
}
return *this;
}
bool LocateRegExpList::isMatchingOne(const TQString& file) const
{
bool matches = false;
LocateRegExpList::ConstIterator it = begin();
for (; !matches && (it != end()); ++it) {
matches = (*it).isMatching(file);
}
return matches;
}
bool LocateRegExpList::isMatchingAll(const TQString& file) const
{
bool matches = true;
LocateRegExpList::ConstIterator it = begin();
for (; matches && (it != end()); ++it) {
matches = (*it).isMatching(file);
}
return matches;
}
|