aboutsummaryrefslogtreecommitdiff
path: root/source/Utility/NameMatches.cpp
blob: 7b733d24eba2e769ffae3e4c3913dcc6bb7d8812 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//===-- 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/Utility/NameMatches.h"
#include "lldb/Core/RegularExpression.h"

#include "llvm/ADT/StringRef.h"

using namespace lldb_private;

bool lldb_private::NameMatches(llvm::StringRef name, NameMatchType match_type,
                               llvm::StringRef match) {
  if (match_type == eNameMatchIgnore)
    return true;

  if (name == match)
    return true;

  if (name.empty() || match.empty())
    return false;

  switch (match_type) {
  case eNameMatchIgnore: // This case cannot occur: tested before
    return true;
  case eNameMatchEquals:
    return name == match;
  case eNameMatchContains:
    return name.contains(match);
  case eNameMatchStartsWith:
    return name.startswith(match);
  case eNameMatchEndsWith:
    return name.endswith(match);
  case eNameMatchRegularExpression: {
    RegularExpression regex(match);
    return regex.Execute(name);
  } break;
  }
  return false;
}