2021-08-02 17:24:11 +08:00
|
|
|
#include "Search.h"
|
|
|
|
|
|
|
|
SynSearch::SynSearch(QObject *parent):SynSearchBase(parent)
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynSearch::length(int aIndex)
|
|
|
|
{
|
|
|
|
if (aIndex<0 || aIndex >= mResults.length())
|
|
|
|
return 0;
|
|
|
|
return pattern().length();
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynSearch::result(int aIndex)
|
|
|
|
{
|
|
|
|
if (aIndex<0 || aIndex >= mResults.length())
|
|
|
|
return -1;
|
|
|
|
return mResults[aIndex];
|
|
|
|
}
|
|
|
|
|
|
|
|
int SynSearch::resultCount()
|
|
|
|
{
|
|
|
|
return mResults.count();
|
|
|
|
}
|
|
|
|
|
2021-10-04 12:49:55 +08:00
|
|
|
int SynSearch::findAll(const QString &text)
|
2021-08-02 17:24:11 +08:00
|
|
|
{
|
|
|
|
mResults.clear();
|
|
|
|
if (pattern().isEmpty())
|
|
|
|
return 0;
|
|
|
|
int start=0;
|
|
|
|
int next=-1;
|
|
|
|
while (true) {
|
2021-08-02 21:58:39 +08:00
|
|
|
if (options().testFlag(ssoMatchCase)) {
|
2021-10-04 12:49:55 +08:00
|
|
|
next = text.indexOf(pattern(),start,Qt::CaseSensitive);
|
2021-08-02 17:24:11 +08:00
|
|
|
} else {
|
2021-10-04 12:49:55 +08:00
|
|
|
next = text.indexOf(pattern(),start,Qt::CaseInsensitive);
|
2021-08-02 17:24:11 +08:00
|
|
|
}
|
|
|
|
if (next<0) {
|
|
|
|
break;
|
|
|
|
}
|
2021-10-04 12:49:55 +08:00
|
|
|
start = next + pattern().length();
|
2021-08-04 09:13:41 +08:00
|
|
|
if (options().testFlag(ssoWholeWord)) {
|
2021-10-04 12:49:55 +08:00
|
|
|
if (((next<=0) || isDelimitChar(text[next-1]))
|
2021-08-04 09:13:41 +08:00
|
|
|
&&
|
2021-10-04 12:49:55 +08:00
|
|
|
( (start>=text.length()) || isDelimitChar(text[start]) )
|
2021-08-04 09:13:41 +08:00
|
|
|
) {
|
|
|
|
mResults.append(next);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mResults.append(next);
|
|
|
|
}
|
|
|
|
|
2021-08-02 17:24:11 +08:00
|
|
|
}
|
|
|
|
return mResults.size();
|
|
|
|
}
|
|
|
|
|
2021-08-29 10:14:07 +08:00
|
|
|
QString SynSearch::replace(const QString &, const QString &aReplacement)
|
2021-08-02 17:24:11 +08:00
|
|
|
{
|
|
|
|
return aReplacement;
|
|
|
|
}
|
2021-08-04 09:13:41 +08:00
|
|
|
|
|
|
|
bool SynSearch::isDelimitChar(QChar ch)
|
|
|
|
{
|
|
|
|
return !(ch == '_' || ch.isLetterOrNumber());
|
|
|
|
}
|