]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Utility/NameMatches.cpp
Merge from vendor branch importing dtc 1.4.3
[FreeBSD/FreeBSD.git] / contrib / llvm / tools / lldb / source / Utility / NameMatches.cpp
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(llvm::StringRef name, NameMatchType match_type,
17                                llvm::StringRef match) {
18   if (match_type == eNameMatchIgnore)
19     return true;
20
21   if (name == match)
22     return true;
23
24   if (name.empty() || match.empty())
25     return false;
26
27   switch (match_type) {
28   case eNameMatchIgnore: // This case cannot occur: tested before
29     return true;
30   case eNameMatchEquals:
31     return name == match;
32   case eNameMatchContains:
33     return name.contains(match);
34   case eNameMatchStartsWith:
35     return name.startswith(match);
36   case eNameMatchEndsWith:
37     return name.endswith(match);
38   case eNameMatchRegularExpression: {
39     RegularExpression regex(match);
40     return regex.Execute(name);
41   } break;
42   }
43   return false;
44 }