summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/NameMatches.cpp
diff options
context:
space:
mode:
authorPavel Labath <labath@google.com>2017-02-20 11:35:33 +0000
committerPavel Labath <labath@google.com>2017-02-20 11:35:33 +0000
commitc4a339510359d57c9d143c350911a2c528201e0e (patch)
tree78411f943bc0b84e7be76c32f649039c6b09ac8e /lldb/source/Utility/NameMatches.cpp
parent55865432b428a80c818e52ce506d8dd98657b1f5 (diff)
downloadbcm5719-llvm-c4a339510359d57c9d143c350911a2c528201e0e.tar.gz
bcm5719-llvm-c4a339510359d57c9d143c350911a2c528201e0e.zip
Fix a couple of corner cases in NameMatches
Summary: I originally set out to move the NameMatches closer to the relevant function and add some unit tests. However, in the process I've found a couple of bugs in the implementation: - the early exits where not always correct: - (test==pattern) does not mean the match will always suceed because of regular expressions - pattern.empty() does not mean the match will fail because the "" is a valid prefix of any string So I cleaned up those and added some tests. The only tricky part here was that regcomp() implementation on darwin did not recognise the empty string as a regular expression and returned an REG_EMPTY error instead. The simples fix here seemed to be to replace the empty expression with an equivalent non-empty one. Reviewers: clayborg, zturner Subscribers: mgorny, lldb-commits Differential Revision: https://reviews.llvm.org/D30094 llvm-svn: 295651
Diffstat (limited to 'lldb/source/Utility/NameMatches.cpp')
-rw-r--r--lldb/source/Utility/NameMatches.cpp25
1 files changed, 8 insertions, 17 deletions
diff --git a/lldb/source/Utility/NameMatches.cpp b/lldb/source/Utility/NameMatches.cpp
index 241fc76232b..a76df3f929e 100644
--- a/lldb/source/Utility/NameMatches.cpp
+++ b/lldb/source/Utility/NameMatches.cpp
@@ -13,32 +13,23 @@
using namespace lldb_private;
-bool lldb_private::NameMatches(llvm::StringRef name, NameMatchType match_type,
+bool lldb_private::NameMatches(llvm::StringRef name, NameMatch match_type,
llvm::StringRef match) {
- if (match_type == eNameMatchIgnore)
- return true;
-
- if (name == match)
- return true;
-
- if (name.empty() || match.empty())
- return false;
-
switch (match_type) {
- case eNameMatchIgnore: // This case cannot occur: tested before
+ case NameMatch::Ignore:
return true;
- case eNameMatchEquals:
+ case NameMatch::Equals:
return name == match;
- case eNameMatchContains:
+ case NameMatch::Contains:
return name.contains(match);
- case eNameMatchStartsWith:
+ case NameMatch::StartsWith:
return name.startswith(match);
- case eNameMatchEndsWith:
+ case NameMatch::EndsWith:
return name.endswith(match);
- case eNameMatchRegularExpression: {
+ case NameMatch::RegularExpression: {
RegularExpression regex(match);
return regex.Execute(name);
- } break;
+ }
}
return false;
}
OpenPOWER on IntegriCloud