1 //===-- NameMatches.cpp -----------------------------------------*- C++ -*-===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 #include "lldb/Utility/NameMatches.h" 10 #include "lldb/Core/RegularExpression.h" 11 12 #include "llvm/ADT/StringRef.h" 13 14 using namespace lldb_private; 15 16 bool lldb_private::NameMatches(const char *name, NameMatchType match_type, 17 const char *match) { 18 if (match_type == eNameMatchIgnore) 19 return true; 20 21 if (name == match) 22 return true; 23 24 if (name && match) { 25 llvm::StringRef name_sref(name); 26 llvm::StringRef match_sref(match); 27 switch (match_type) { 28 case eNameMatchIgnore: // This case cannot occur: tested before 29 return true; 30 case eNameMatchEquals: 31 return name_sref == match_sref; 32 case eNameMatchContains: 33 return name_sref.find(match_sref) != llvm::StringRef::npos; 34 case eNameMatchStartsWith: 35 return name_sref.startswith(match_sref); 36 case eNameMatchEndsWith: 37 return name_sref.endswith(match_sref); 38 case eNameMatchRegularExpression: { 39 RegularExpression regex(match_sref); 40 return regex.Execute(name_sref); 41 } break; 42 } 43 } 44 return false; 45 } 46