ESPHome
2026.11.0-dev
Loading...
Searching...
No Matches
esphome
components
mqtt
mqtt_topic_match.h
Go to the documentation of this file.
1
#pragma once
2
3
namespace
esphome::mqtt
{
4
7
inline
bool
topic_match
(
const
char
*
message
,
const
char
*subscription) {
8
// First-level wildcards do not match topics that begin with '$'
9
bool
wildcards = *
message
!=
'$'
;
10
while
(*
message
!=
'\0'
&& *subscription !=
'\0'
) {
11
if
(wildcards && *subscription ==
'#'
)
12
return
true
;
13
if
(wildcards && *subscription ==
'+'
) {
14
subscription++;
15
while
(*
message
!=
'\0'
&& *
message
!=
'/'
)
16
message
++;
17
continue
;
18
}
19
if
(*
message
!= *subscription)
20
return
false
;
21
wildcards |= *subscription ==
'/'
;
22
message
++;
23
subscription++;
24
}
25
return
*
message
== *subscription;
// a match only if both ended
26
}
27
28
}
// namespace esphome::mqtt
message
const LogString * message
Definition
component.cpp:35
esphome::mqtt
Definition
custom_mqtt_device.cpp:7
esphome::mqtt::topic_match
bool topic_match(const char *message, const char *subscription)
True if the message topic matches the subscription, with + and # wildcards.
Definition
mqtt_topic_match.h:7
Generated by
1.12.0