4#ifdef USE_TEXT_SENSOR_FILTER
35 void input(std::string value);
37 void output(std::string &value);
58 bool new_value(std::string &value)
override;
78 if (result.has_value()) {
79 value = std::move(*result);
92 bool new_value(std::string &value)
override;
98 bool new_value(std::string &value)
override;
105 bool new_value(std::string &value)
override;
115 bool new_value(std::string &value)
override;
143bool map_filter_apply(
const Substitution *mappings,
size_t count, std::string &value);
173 explicit MapFilter(
const std::initializer_list<Substitution> &mappings) {
A simple filter that adds a string to the end of another string.
bool new_value(std::string &value) override
AppendFilter(const char *suffix)
Apply a filter to text sensor values such as to_upper.
virtual bool new_value(std::string &value)=0
This will be called every time the filter receives a new value.
void output(std::string &value)
void input(std::string value)
virtual void initialize(TextSensor *parent, Filter *next)
Initialize this filter, please note this can be called more than once.
This class allows for creation of simple template filters.
lambda_filter_t lambda_filter_
LambdaFilter(lambda_filter_t lambda_filter)
void set_lambda_filter(const lambda_filter_t &lambda_filter)
bool new_value(std::string &value) override
const lambda_filter_t & get_lambda_filter() const
A filter that maps values from one set to another.
std::array< Substitution, N > mappings_
bool new_value(std::string &value) override
MapFilter(const std::initializer_list< Substitution > &mappings)
A simple filter that adds a string to the start of another string.
bool new_value(std::string &value) override
PrependFilter(const char *prefix)
Optimized lambda filter for stateless lambdas (no capture).
optional< std::string >(* lambda_filter_)(std::string)
StatelessLambdaFilter(optional< std::string >(*lambda_filter)(std::string))
bool new_value(std::string &value) override
A simple filter that replaces a substring with another substring.
bool new_value(std::string &value) override
std::array< Substitution, N > substitutions_
SubstituteFilter(const std::initializer_list< Substitution > &substitutions)
A simple filter that converts all text to lowercase.
bool new_value(std::string &value) override
A simple filter that converts all text to uppercase.
bool new_value(std::string &value) override
std::function< optional< std::string >(std::string)> lambda_filter_t
bool map_filter_apply(const Substitution *mappings, size_t count, std::string &value)
Non-template helper (implementation in filter.cpp)
bool substitute_filter_apply(const Substitution *substitutions, size_t count, std::string &value)
Non-template helper (implementation in filter.cpp)
void init_array_from(std::array< T, N > &dest, std::initializer_list< T > src)
Initialize a std::array from an initializer_list.