blob: 1c8cd6a0ca31dfd288cc6cbadd4d00daac64b984 [file] [log] [blame]
Raphael Isemann80814282020-01-24 08:23:27 +01001//===-- NameMatches.cpp ---------------------------------------------------===//
Zachary Turner50232572015-03-18 21:31:45 +00002//
Chandler Carruth2946cd72019-01-19 08:50:56 +00003// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Zachary Turner50232572015-03-18 21:31:45 +00006//
7//===----------------------------------------------------------------------===//
Zachary Turner50232572015-03-18 21:31:45 +00008#include "lldb/Utility/NameMatches.h"
Zachary Turnerbf9a7732017-02-02 21:39:50 +00009#include "lldb/Utility/RegularExpression.h"
Zachary Turner50232572015-03-18 21:31:45 +000010
11#include "llvm/ADT/StringRef.h"
12
13using namespace lldb_private;
14
Pavel Labathc4a33952017-02-20 11:35:33 +000015bool lldb_private::NameMatches(llvm::StringRef name, NameMatch match_type,
Zachary Turner4aa87532016-11-17 01:37:42 +000016 llvm::StringRef match) {
Zachary Turner4aa87532016-11-17 01:37:42 +000017 switch (match_type) {
Pavel Labathc4a33952017-02-20 11:35:33 +000018 case NameMatch::Ignore:
Zachary Turner4aa87532016-11-17 01:37:42 +000019 return true;
Pavel Labathc4a33952017-02-20 11:35:33 +000020 case NameMatch::Equals:
Zachary Turner4aa87532016-11-17 01:37:42 +000021 return name == match;
Pavel Labathc4a33952017-02-20 11:35:33 +000022 case NameMatch::Contains:
Zachary Turner4aa87532016-11-17 01:37:42 +000023 return name.contains(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000024 case NameMatch::StartsWith:
Zachary Turner4aa87532016-11-17 01:37:42 +000025 return name.startswith(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000026 case NameMatch::EndsWith:
Zachary Turner4aa87532016-11-17 01:37:42 +000027 return name.endswith(match);
Pavel Labathc4a33952017-02-20 11:35:33 +000028 case NameMatch::RegularExpression: {
Zachary Turner4aa87532016-11-17 01:37:42 +000029 RegularExpression regex(match);
30 return regex.Execute(name);
Pavel Labathc4a33952017-02-20 11:35:33 +000031 }
Kate Stoneb9c1b512016-09-06 20:57:50 +000032 }
33 return false;
Zachary Turner50232572015-03-18 21:31:45 +000034}