diff --git a/esphome/components/dynamic_lamp/dynamic_lamp.cpp b/esphome/components/dynamic_lamp/dynamic_lamp.cpp index b685049730..7bc11d6ebc 100644 --- a/esphome/components/dynamic_lamp/dynamic_lamp.cpp +++ b/esphome/components/dynamic_lamp/dynamic_lamp.cpp @@ -1,7 +1,10 @@ #include "esphome/core/log.h" #include "esphome/core/helpers.h" #include "dynamic_lamp.h" -#include +#include +#include +#include +#include namespace esphome { namespace dynamic_lamp { @@ -91,7 +94,7 @@ void DynamicLamp::set_available_outputs(std::string output_list) { for ( std::string s : v ) { std::string id_string; - id_string = boost::algorithm::trim(s.c_str()); + id_string = this->trim_(s.c_str()); this->available_outputs_[counter] = id_string; counter++; } @@ -108,5 +111,26 @@ void DynamicLamp::restore_lamp_values_(uint8_t lamp_number) { this->active_lamps_[lamp_number].active = false; } +std::string_view DynamicLamp::ltrim_(std::string_view str) +{ + const auto pos(str.find_first_not_of(" \t\n\r\f\v")); + str.remove_prefix(std::min(pos, str.length())); + return str; +} + +std::string_view DynamicLamp::rtrim_(std::string_view str) +{ + const auto pos(str.find_last_not_of(" \t\n\r\f\v")); + str.remove_suffix(std::min(str.length() - pos - 1, str.length())); + return str; +} + +std::string_view DynamicLamp::trim_(std::string_view str) +{ + str = ltrim(str); + str = rtrim(str); + return str; +} + } // namespace dynamic_lamp } // namespace esphome diff --git a/esphome/components/dynamic_lamp/dynamic_lamp.h b/esphome/components/dynamic_lamp/dynamic_lamp.h index b8af5a7ccf..abe56156e0 100644 --- a/esphome/components/dynamic_lamp/dynamic_lamp.h +++ b/esphome/components/dynamic_lamp/dynamic_lamp.h @@ -1,7 +1,6 @@ #pragma once #include "esphome/core/component.h" -#include namespace esphome { namespace dynamic_lamp { @@ -44,6 +43,9 @@ class DynamicLamp : public Component { protected: void restore_lamp_values_(uint8_t lamp_number); void set_lamp_values_(uint8_t lamp_number, bool active, uint16_t selected_outputs, uint8_t mode, uint8_t mode_value); + std::stringview ltrim_(std::string_view str); + std::string_view rtrim_(std::string_view str); + std::string_view trim_(std::string_view str); CombinedLamp active_lamps_[16]; std::string available_outputs_[16] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };