blob: a76df3f929e8b0fd3150f11f763fab66f0bc20d8 [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"
Zachary Turnerbf9a7732017-02-02 21:39:50 +000010#include "lldb/Utility/RegularExpression.h"
Zachary Turner50232572015-03-18 21:31:45 +000011
12#include "llvm/ADT/StringRef.h"
13
14using namespace lldb_private;
15
Pavel Labathc4a33952017-02-20 11:35:33 +000016bool lldb_private::NameMatches(llvm::StringRef name, NameMatch match_type,
Zachary Turner4aa87532016-11-17 01:37:42 +000017 llvm::StringRef match) {
Zachary Turner4aa87532016-11-17 01:37:42 +000018 switch (match_type) {
Pavel Labathc4a33952017-02-20 11:35:33 +000019 case NameMatch::Ignore:
Zachary Turner4aa87532016-11-17 01:37:42 +000020 return true;
Pavel Labathc4a33952017-02-20 11:35:33 +000021 case NameMatch::Equals:
Zachary Turner4aa87532016-11-17 01:37:42 +000022 return name == match;
Pavel Labathc4a33952017-02-20 11:35:33 +000023 case NameMatch::Contains:
Zachary Turner4aa87532016-11-17 01:37:42 +000024 return name.contains(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000025 case NameMatch::StartsWith:
Zachary Turner4aa87532016-11-17 01:37:42 +000026 return name.startswith(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000027 case NameMatch::EndsWith:
Zachary Turner4aa87532016-11-17 01:37:42 +000028 return name.endswith(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000029 case NameMatch::RegularExpression: {
Zachary Turner4aa87532016-11-17 01:37:42 +000030 RegularExpression regex(match);
31 return regex.Execute(name);
Pavel Labathc4a33952017-02-20 11:35:33 +000032 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000033 }
34 return false;
Zachary Turner50232572015-03-18 21:31:45 +000035}