diff options
| author | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
|---|---|---|
| committer | Ed Maste <emaste@FreeBSD.org> | 2015-07-03 16:57:06 +0000 |
| commit | 5e95aa85bb660d45e9905ef1d7180b2678280660 (patch) | |
| tree | 3c2e41c3be19b7fc7666ed45a5f91ec3b6e35f2a /source/Utility/NameMatches.cpp | |
| parent | 12bd4897ff0678fa663e09d78ebc22dd255ceb86 (diff) | |
Notes
Diffstat (limited to 'source/Utility/NameMatches.cpp')
| -rw-r--r-- | source/Utility/NameMatches.cpp | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/source/Utility/NameMatches.cpp b/source/Utility/NameMatches.cpp new file mode 100644 index 000000000000..e10c47e4fd9b --- /dev/null +++ b/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; +} |
