1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-10 15:22:24 +01:00

refactor: replace boost::algorithm::trim with custom string trimming methods

This commit is contained in:
Oliver Kleinecke
2025-02-14 14:55:50 +01:00
parent b8c389829d
commit 8d0185aafe
2 changed files with 29 additions and 3 deletions

View File

@@ -1,7 +1,10 @@
#include "esphome/core/log.h" #include "esphome/core/log.h"
#include "esphome/core/helpers.h" #include "esphome/core/helpers.h"
#include "dynamic_lamp.h" #include "dynamic_lamp.h"
#include <regex> #include <string>
#include <cstring>
#include <stringview>
#include <vector>
namespace esphome { namespace esphome {
namespace dynamic_lamp { namespace dynamic_lamp {
@@ -91,7 +94,7 @@ void DynamicLamp::set_available_outputs(std::string output_list) {
for ( std::string s : v ) for ( std::string s : v )
{ {
std::string id_string; 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; this->available_outputs_[counter] = id_string;
counter++; counter++;
} }
@@ -108,5 +111,26 @@ void DynamicLamp::restore_lamp_values_(uint8_t lamp_number) {
this->active_lamps_[lamp_number].active = false; 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 dynamic_lamp
} // namespace esphome } // namespace esphome

View File

@@ -1,7 +1,6 @@
#pragma once #pragma once
#include "esphome/core/component.h" #include "esphome/core/component.h"
#include <boost/algorithm/string/trim.hpp>
namespace esphome { namespace esphome {
namespace dynamic_lamp { namespace dynamic_lamp {
@@ -44,6 +43,9 @@ class DynamicLamp : public Component {
protected: protected:
void restore_lamp_values_(uint8_t lamp_number); 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); 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]; CombinedLamp active_lamps_[16];
std::string available_outputs_[16] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" }; std::string available_outputs_[16] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };