Skip to content

Commit 5bfd349

Browse files
committed
Use isMatch function to remove duplicated codes
1 parent 52c47b2 commit 5bfd349

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

examples/chef/common/clusters/channel/ChannelManager.cpp

+5-6
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,12 @@ bool isChannelMatched(const ChannelInfoType & channel, const CharSpan & match)
141141
ss << channel.majorNumber << "." << channel.minorNumber;
142142
std::string number = ss.str();
143143

144-
bool nameMatch = channel.name.HasValue() ? channel.name.Value().data_equal(match) : false;
145-
bool affiliateCallSignMatch =
146-
channel.affiliateCallSign.HasValue() ? channel.affiliateCallSign.Value().data_equal(match) : false;
147-
bool callSignMatch = channel.callSign.HasValue() ? channel.callSign.Value().data_equal(match) : false;
148-
bool numberMatch = match.data_equal(chip::CharSpan::fromCharString(number.c_str()));
144+
auto isMatch = [&match](const Optional<chip::CharSpan> &a)
145+
{
146+
return a.HasValue() && a.Value().data_equal(match);
147+
};
149148

150-
return affiliateCallSignMatch || callSignMatch || nameMatch || numberMatch;
149+
return isMatch(channel.name) || isMatch(channel.affiliateCallSign) || isMatch(channel.callSign) || match.data_equal(chip::CharSpan::fromCharString(number.c_str()));
151150
}
152151

153152
void ChannelManager::HandleChangeChannel(CommandResponseHelper<ChangeChannelResponseType> & helper, const CharSpan & match)

0 commit comments

Comments
 (0)