blob: bd30760d7e6157bac2a731487cea67ec1af6a8ae [file] [log] [blame]
Zachary Turner50232572015-03-18 21:31:45 +00001//===-- 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//===----------------------------------------------------------------------===//
Zachary Turner50232572015-03-18 21:31:45 +00009#include "lldb/Utility/NameMatches.h"
Kate Stoneb9c1b512016-09-06 20:57:50 +000010#include "lldb/Core/RegularExpression.h"
Zachary Turner50232572015-03-18 21:31:45 +000011
12#include "llvm/ADT/StringRef.h"
13
14using namespace lldb_private;
15
Kate Stoneb9c1b512016-09-06 20:57:50 +000016bool lldb_private::NameMatches(const char *name, NameMatchType match_type,
17 const char *match) {
18 if (match_type == eNameMatchIgnore)
19 return true;
Zachary Turner50232572015-03-18 21:31:45 +000020
Kate Stoneb9c1b512016-09-06 20:57:50 +000021 if (name == match)
22 return true;
Zachary Turner50232572015-03-18 21:31:45 +000023
Kate Stoneb9c1b512016-09-06 20:57:50 +000024 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);
40 return regex.Execute(name);
41 } break;
Zachary Turner50232572015-03-18 21:31:45 +000042 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000043 }
44 return false;
Zachary Turner50232572015-03-18 21:31:45 +000045}