Some minor and small fixes
This commit is contained in:
parent
38cebf23a1
commit
d2720897c4
@ -317,37 +317,45 @@ namespace ts {
|
||||
template <typename vector_t = std::vector<std::string>>
|
||||
class command_builder_impl {
|
||||
public:
|
||||
explicit command_builder_impl(std::string command, size_t expected_bulk_size = 128, size_t expected_bulks = 1) : _identifier{std::move(command)}, expected_bulk_size{expected_bulk_size} {
|
||||
explicit command_builder_impl(std::string command, size_t expected_bulk_size = 128, size_t expected_bulks = 1) : identifier_{std::move(command)}, expected_bulk_size{expected_bulk_size} {
|
||||
for(size_t index = 0; index < expected_bulks; index++)
|
||||
this->bulks.emplace_back(" ").reserve(expected_bulk_size);
|
||||
this->bulks.emplace_back("").reserve(expected_bulk_size);
|
||||
}
|
||||
|
||||
inline command_builder_impl<std::vector<std::string>> as_normalized() {
|
||||
return command_builder_impl<std::vector<std::string>>{this->expected_bulk_size, this->_identifier, this->bulks.begin(), this->bulks.end()};
|
||||
return command_builder_impl<std::vector<std::string>>{this->expected_bulk_size, this->identifier_, this->bulks.begin(), this->bulks.end()};
|
||||
}
|
||||
|
||||
inline std::string build(bool with_empty = false) const {
|
||||
if(this->builded.has_value() && !this->flag_changed)
|
||||
if(this->builded.has_value() && !this->flag_changed) {
|
||||
return this->builded.value();
|
||||
}
|
||||
|
||||
std::string result{};
|
||||
size_t required_size{this->_identifier.size()};
|
||||
for(auto& entry : this->bulks)
|
||||
size_t required_size{this->identifier_.size()};
|
||||
for(auto& entry : this->bulks) {
|
||||
required_size += entry.size() + 1;
|
||||
}
|
||||
|
||||
result.append(this->identifier_);
|
||||
|
||||
result.append(this->_identifier);
|
||||
for(auto it = this->bulks.begin(); it != this->bulks.end(); it++) {
|
||||
if(it->empty() && !with_empty) continue;
|
||||
if(it->empty() && !with_empty) {
|
||||
continue;
|
||||
}
|
||||
|
||||
result.append(*it, 0, it->length() - 1);
|
||||
if(it + 1 != this->bulks.end())
|
||||
if(it + 1 != this->bulks.end()) {
|
||||
result.append("|");
|
||||
}
|
||||
}
|
||||
|
||||
if(!with_empty && !result.empty() && result.back() == '|') {
|
||||
this->builded = result.substr(0, result.length() - 1);
|
||||
} else {
|
||||
this->builded = result;
|
||||
}
|
||||
|
||||
this->flag_changed = false;
|
||||
return this->builded.value();
|
||||
}
|
||||
@ -398,10 +406,10 @@ namespace ts {
|
||||
bulk = " ";
|
||||
}
|
||||
private:
|
||||
command_builder_impl(size_t expected, std::string identifier, typename vector_t::iterator begin, typename vector_t::iterator end) : expected_bulk_size{expected}, _identifier{std::move(identifier)}, bulks{begin, end} {}
|
||||
command_builder_impl(size_t expected, std::string identifier, typename vector_t::iterator begin, typename vector_t::iterator end) : expected_bulk_size{expected}, identifier_{std::move(identifier)}, bulks{begin, end} {}
|
||||
|
||||
const size_t expected_bulk_size;
|
||||
const std::string _identifier;
|
||||
const std::string identifier_;
|
||||
mutable bool flag_changed{false};
|
||||
mutable std::optional<std::string> builded{};
|
||||
vector_t bulks{};
|
||||
|
Loading…
x
Reference in New Issue
Block a user