1010#include < utility>
1111#include < chrono>
1212#include < type_traits>
13+ #include < iterator>
14+ #include < format>
1315#include " input_sanitizer.h"
14- #include < fmt/format.h>
1516
1617namespace influxdb {
1718
1819 namespace api {
1920
2021 // https://docs.influxdata.com/influxdb/v1.0/write_protocols/line_protocol_tutorial/
2122 class key_value_pairs {
22- fmt::memory_buffer res;
23+ std::string res;
2324
2425 public:
2526
2627 key_value_pairs () {};
2728 ~key_value_pairs () {};
2829
2930 key_value_pairs (key_value_pairs const & other) {
30- format_to (res, " {}" , other.get ());
31+ std:: format_to (std::back_inserter ( res) , " {}" , other.get ());
3132 }
3233
3334 key_value_pairs& operator =(key_value_pairs const & other) {
34- format_to (res, " {}" , other.get ());
35+ std:: format_to (std::back_inserter ( res) , " {}" , other.get ());
3536 return *this ;
3637 }
3738
@@ -57,7 +58,7 @@ namespace influxdb {
5758
5859 add_comma_if_necessary ();
5960
60- format_to (res, " {}={}i" , key, value);
61+ std:: format_to (std::back_inserter ( res) , " {}={}i" , key, value);
6162
6263 return *this ;
6364 }
@@ -74,7 +75,7 @@ namespace influxdb {
7475
7576 add_comma_if_necessary ();
7677
77- format_to (res, " {}={}" , key, value);
78+ std:: format_to (std::back_inserter ( res) , " {}={}" , key, value);
7879
7980 return *this ;
8081 }
@@ -90,7 +91,7 @@ namespace influxdb {
9091
9192 add_comma_if_necessary ();
9293
93- format_to (res, " {}={}" , key, value);
94+ std:: format_to (std::back_inserter ( res) , " {}={}" , key, value);
9495
9596 return *this ;
9697 }
@@ -100,23 +101,23 @@ namespace influxdb {
100101
101102 add_comma_if_necessary ();
102103
103- format_to (res, " {}=\" {}\" " , key, value);
104+ std:: format_to (std::back_inserter ( res) , " {}=\" {}\" " , key, value);
104105
105106 return *this ;
106107 }
107108
108109 inline std::string get () const {
109- return std::string ( res. data (),res. size ()) ;
110+ return res;
110111 }
111112
112113 inline bool empty () const {
113- return ! res.size ();
114+ return res.empty ();
114115 }
115116
116117 private:
117118 inline void add_comma_if_necessary () {
118119 if (!this ->empty ())
119- format_to (res, " ," );
120+ std:: format_to (std::back_inserter ( res) , " ," );
120121 }
121122 };
122123
@@ -131,68 +132,68 @@ namespace influxdb {
131132
132133 // / simplest, probably slow implementation
133134 class line {
134- fmt::memory_buffer res;
135+ std::string res;
135136
136137 public:
137138 line () {};
138139 ~line () {};
139140
140141 line& operator =(line const & other) {
141- format_to (res, " {}" , other.get ());
142+ std:: format_to (std::back_inserter ( res) , " {}" , other.get ());
142143 return *this ;
143144 }
144145
145146 line (line const & other) {
146- format_to (res, " {}" , other.get ());
147+ std:: format_to (std::back_inserter ( res) , " {}" , other.get ());
147148 }
148149
149150 line (line && other) {
150151 res = std::move (other.res );
151152 }
152153
153154 explicit line (std::string const & raw) {
154- format_to (res, " {}" , raw);
155+ std:: format_to (std::back_inserter ( res) , " {}" , raw);
155156 }
156157
157158 template <typename TTimestamp>
158159 explicit line (std::string const & raw, TTimestamp const & timestamp) {
159- format_to (res, " {} {}" , raw, timestamp.now ());
160+ std:: format_to (std::back_inserter ( res) , " {} {}" , raw, timestamp.now ());
160161 }
161162
162163 template <typename TMap>
163164 inline line (std::string const & measurement, TMap const & tags, TMap const & values) {
164165 ::influxdb::utility::throw_on_invalid_identifier (measurement);
165166
166- format_to (res, " {}" , measurement);
167+ std:: format_to (std::back_inserter ( res) , " {}" , measurement);
167168 if (!tags.empty ()) {
168- format_to (res, " ,{}" , tags.get ());
169+ std:: format_to (std::back_inserter ( res) , " ,{}" , tags.get ());
169170 }
170171
171172 if (!values.empty ()) {
172- format_to (res, " {}" , values.get ());
173+ std:: format_to (std::back_inserter ( res) , " {}" , values.get ());
173174 }
174175 }
175176
176177 template <typename TMap,typename TTimestamp>
177178 inline line (std::string const & measurement, TMap const & tags, TMap const & values, TTimestamp const & timestamp):
178179 line(measurement, tags, values) {
179- format_to (res, " {}" , timestamp.now ());
180+ std:: format_to (std::back_inserter ( res) , " {}" , timestamp.now ());
180181 }
181182
182183 template <typename TMap>
183184 inline line& operator ()(std::string const & measurement, TMap const & tags, TMap const & values) {
184- format_to (res, " \n {}" , line (measurement, tags, values).get ());
185+ std:: format_to (std::back_inserter ( res) , " \n {}" , line (measurement, tags, values).get ());
185186 return *this ;
186187 }
187188
188189 template <typename TMap, typename TTimestamp>
189190 inline line& operator ()(std::string const & measurement, TMap const & tags, TMap const & values, TTimestamp const & timestamp) {
190- format_to (res, " \n {}" , line (measurement, tags, values, timestamp).get ());
191+ std:: format_to (std::back_inserter ( res) , " \n {}" , line (measurement, tags, values, timestamp).get ());
191192 return *this ;
192193 }
193194 public:
194195 inline std::string get () const {
195- return std::string ( res. data (),res. size ()) ;
196+ return res;
196197 }
197198 };
198199
0 commit comments