Better command builder format output like ts3 expects it
This commit is contained in:
parent
d13c1e6d68
commit
4aec154ff1
@ -143,7 +143,7 @@ namespace ts {
|
||||
return command_builder_impl<std::vector<std::string>>{this->expected_bulk_size, this->_identifier, this->bulks.begin(), this->bulks.end()};
|
||||
}
|
||||
|
||||
inline std::string build() const {
|
||||
inline std::string build(bool with_empty = false) const {
|
||||
if(this->builded.has_value())
|
||||
return this->builded.value();
|
||||
|
||||
@ -154,20 +154,24 @@ namespace ts {
|
||||
|
||||
result.append(this->_identifier);
|
||||
for(auto it = this->bulks.begin(); it != this->bulks.end(); it++) {
|
||||
result.append(*it);
|
||||
if(it->empty() && !with_empty) continue;
|
||||
|
||||
result.append(*it, 0, it->length() - 1);
|
||||
if(it + 1 != this->bulks.end())
|
||||
result.append("|");
|
||||
}
|
||||
|
||||
if(!with_empty && result.ends_with('|'))
|
||||
this->builded = result.substr(0, result.length() - 1);
|
||||
else
|
||||
this->builded = result;
|
||||
return result;
|
||||
return this->builded.value();
|
||||
}
|
||||
|
||||
inline void reserve_bulks(size_t count) { this->bulks.reserve(count); }
|
||||
|
||||
inline void put(size_t index, const std::string_view& key, const std::string_view& value) {
|
||||
while(this->bulks.size() <= index)
|
||||
this->bulks.emplace_back(" ").reserve(expected_bulk_size);
|
||||
this->bulks.emplace_back("").reserve(expected_bulk_size);
|
||||
|
||||
auto& data = this->bulks[index];
|
||||
size_t begin, end;
|
||||
@ -193,7 +197,7 @@ namespace ts {
|
||||
/* directly puts data without checking for duplicates */
|
||||
inline void put_unchecked(size_t index, const std::string_view& key, const std::string_view& value) {
|
||||
while(this->bulks.size() <= index)
|
||||
this->bulks.emplace_back(" ").reserve(expected_bulk_size);
|
||||
this->bulks.emplace_back("").reserve(expected_bulk_size);
|
||||
|
||||
this->impl_put_unchecked(this->bulks[index], index, key, value);
|
||||
}
|
||||
@ -217,8 +221,10 @@ namespace ts {
|
||||
|
||||
data.reserve(data.length() + key.size() + escaped_value.size() + 2);
|
||||
data.append(key);
|
||||
if(!escaped_value.empty()) {
|
||||
data.append("=");
|
||||
data.append(escaped_value);
|
||||
}
|
||||
data.append(" ");
|
||||
|
||||
this->builded.reset();
|
||||
|
Loading…
Reference in New Issue
Block a user