QString matching.
-
-
I have two QStringLists with include and exclude values. This mean if I make a loop for target list(with my filenames) I need first look the matching to all of the includes values list, and if includes list is empty I need to look in excludes. So I make the function:
@bool include(const QString & name)
{
bool bInclude = false;if(!indcludes.isEmpty())
{
for(int i = 0; i<indcludes.count();i++)
{
if(name.contains(indcludes.at(i)))
bInclude = true;
}
}
else
bInclude = true;if(!exludes.isEmpty())
{
for(int i = 0; i<exludes.count();i++)
{
if(name.contains(exludes.at(i)))
bInclude = false;
}
}return bInclude;
}@
Here I use contains() function, but it's not correct, because I need to match with mask. -
I gather from your description that this function takes a filename and you want to check whether to include or exclude it by going through two lists with filename masks.
Untested, but it is the first code I would try:
@bool include(const QString &name)
{
bool result = includes.isEmpty();foreach (const QString &pattern, includes) { if (QRegExp(pattern, Qt::CaseInsensitive).exactMatch(name)) result = true; } foreach (const QString &pattern, excludes) { if (QRegExp(pattern, Qt::CaseInsensitive).exactMatch(name)) result = false; } return result;
}@
-
Nope this code:
@bool include(const QString &name)
{
bool result = includes.isEmpty();foreach (const QString &pattern, includes) { if (QRegExp(pattern, Qt::CaseInsensitive).exactMatch(name)) result = true; } foreach (const QString &pattern, excludes) { if (QRegExp(pattern, Qt::CaseInsensitive).exactMatch(name)) result = false; } return result;
}@
does not work. If i set mask *.cpp it skips all of my files. But there are lot of filename strings like this:
.\file.cpp