]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/llvm/tools/lldb/source/Utility/NameMatches.cpp
Merge ^/vendor/NetBSD/tests/dist@r312294
[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/Core/RegularExpression.h"
10 #include "lldb/Utility/NameMatches.h"
11
12 #include "llvm/ADT/StringRef.h"
13
14 using namespace lldb_private;
15
16 bool
17 lldb_private::NameMatches(const char *name, NameMatchType match_type, const char *match)
18 {
19     if (match_type == eNameMatchIgnore)
20         return true;
21
22     if (name == match)
23         return true;
24
25     if (name && match)
26     {
27         llvm::StringRef name_sref(name);
28         llvm::StringRef match_sref(match);
29         switch (match_type)
30         {
31             case eNameMatchIgnore: // This case cannot occur: tested before
32                 return true;
33             case eNameMatchEquals:
34                 return name_sref == match_sref;
35             case eNameMatchContains:
36                 return name_sref.find(match_sref) != llvm::StringRef::npos;
37             case eNameMatchStartsWith:
38                 return name_sref.startswith(match_sref);
39             case eNameMatchEndsWith:
40                 return name_sref.endswith(match_sref);
41             case eNameMatchRegularExpression:
42             {
43                 RegularExpression regex(match);
44                 return regex.Execute(name);
45             }
46             break;
47         }
48     }
49     return false;
50 }