diff --git a/src/query/command3.h b/src/query/command3.h index 53e44d4..5bc8e80 100644 --- a/src/query/command3.h +++ b/src/query/command3.h @@ -143,7 +143,7 @@ namespace ts { return command_builder_impl>{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("|"); } - - this->builded = result; - return result; + if(!with_empty && result.ends_with('|')) + this->builded = result.substr(0, result.length() - 1); + else + this->builded = 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); - data.append("="); - data.append(escaped_value); + if(!escaped_value.empty()) { + data.append("="); + data.append(escaped_value); + } data.append(" "); this->builded.reset();