1 //===-- LogFilterExactMatch.cpp ---------------------------------*- C++ -*-===// 2 // 3 // 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 6 // 7 //===----------------------------------------------------------------------===// 8 9 #include "LogFilterExactMatch.h" 10 #include "LogMessage.h" 11 LogFilterExactMatch(bool match_accepts,FilterTarget filter_target,const std::string & match_text)12LogFilterExactMatch::LogFilterExactMatch(bool match_accepts, 13 FilterTarget filter_target, 14 const std::string &match_text) 15 : LogFilter(match_accepts), m_filter_target(filter_target), 16 m_match_text(match_text) {} 17 DoesMatch(const LogMessage & message) const18bool LogFilterExactMatch::DoesMatch(const LogMessage &message) const { 19 switch (m_filter_target) { 20 case eFilterTargetActivity: 21 // Empty fields never match a condition. 22 if (!message.HasActivity()) 23 return false; 24 return m_match_text == message.GetActivity(); 25 case eFilterTargetActivityChain: 26 // Empty fields never match a condition. 27 if (!message.HasActivity()) 28 return false; 29 return m_match_text == message.GetActivityChain(); 30 case eFilterTargetCategory: 31 // Empty fields never match a condition. 32 if (!message.HasCategory()) 33 return false; 34 return m_match_text == message.GetCategory(); 35 case eFilterTargetMessage: { 36 const char *message_text = message.GetMessage(); 37 return (message_text != nullptr) && (m_match_text == message_text); 38 } 39 case eFilterTargetSubsystem: 40 // Empty fields never match a condition. 41 if (!message.HasSubsystem()) 42 return false; 43 return m_match_text == message.GetSubsystem(); 44 default: 45 // We don't know this type. 46 return false; 47 } 48 } 49