1
0
mirror of https://github.com/esphome/esphome.git synced 2025-09-09 23:02:23 +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/helpers.h"
#include "dynamic_lamp.h"
#include <regex>
#include <string>
#include <cstring>
#include <stringview>
#include <vector>
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