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:
@@ -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
|
||||||
|
@@ -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] = { "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "" };
|
||||||
|
Reference in New Issue
Block a user