summaryrefslogtreecommitdiffstats
path: root/lldb/source/Utility/NameMatches.cpp
diff options
context:
space:
mode:
authorZachary Turner <zturner@google.com>2015-03-18 21:31:45 +0000
committerZachary Turner <zturner@google.com>2015-03-18 21:31:45 +0000
commit5023257f2359d16357721635a22db8ecd7213343 (patch)
tree00a0614090a6113db25735521f32f6361a452d7f /lldb/source/Utility/NameMatches.cpp
parenteba5227ccd4ab2e31e62fe1cdaa811b2da665e90 (diff)
downloadbcm5719-llvm-5023257f2359d16357721635a22db8ecd7213343.tar.gz
bcm5719-llvm-5023257f2359d16357721635a22db8ecd7213343.zip
Move some functions from source/lldb.cpp to Utility.
Specifically, there were some functions for converting enums to strings and a function for matching a string using a specific matching algorithm. This moves those functions to more appropriate headers in lldb/Utility and updates references to include the new headers. llvm-svn: 232673
Diffstat (limited to 'lldb/source/Utility/NameMatches.cpp')
-rw-r--r--lldb/source/Utility/NameMatches.cpp50
1 files changed, 50 insertions, 0 deletions
diff --git a/lldb/source/Utility/NameMatches.cpp b/lldb/source/Utility/NameMatches.cpp
new file mode 100644
index 00000000000..e10c47e4fd9
--- /dev/null
+++ b/lldb/source/Utility/NameMatches.cpp
@@ -0,0 +1,50 @@
+//===-- NameMatches.cpp -----------------------------------------*- C++ -*-===//
+//
+// The LLVM Compiler Infrastructure
+//
+// This file is distributed under the University of Illinois Open Source
+// License. See LICENSE.TXT for details.
+//
+//===----------------------------------------------------------------------===//
+#include "lldb/Core/RegularExpression.h"
+#include "lldb/Utility/NameMatches.h"
+
+#include "llvm/ADT/StringRef.h"
+
+using namespace lldb_private;
+
+bool
+lldb_private::NameMatches(const char *name, NameMatchType match_type, const char *match)
+{
+ if (match_type == eNameMatchIgnore)
+ return true;
+
+ if (name == match)
+ return true;
+
+ if (name && match)
+ {
+ llvm::StringRef name_sref(name);
+ llvm::StringRef match_sref(match);
+ switch (match_type)
+ {
+ case eNameMatchIgnore: // This case cannot occur: tested before
+ return true;
+ case eNameMatchEquals:
+ return name_sref == match_sref;
+ case eNameMatchContains:
+ return name_sref.find(match_sref) != llvm::StringRef::npos;
+ case eNameMatchStartsWith:
+ return name_sref.startswith(match_sref);
+ case eNameMatchEndsWith:
+ return name_sref.endswith(match_sref);
+ case eNameMatchRegularExpression:
+ {
+ RegularExpression regex(match);
+ return regex.Execute(name);
+ }
+ break;
+ }
+ }
+ return false;
+}
OpenPOWER on IntegriCloud