Skip to content

Commit e35cb57

Browse files
authored
Merge pull request #1869 from joto/refactor-build-conninfo
Refactor assembly of connection string components using util::join()
2 parents 786bb9f + e16b4ab commit e35cb57

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/options.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,33 +254,33 @@ std::string build_conninfo(database_options_t const &opt)
254254
return opt.db;
255255
}
256256

257-
std::string out{"fallback_application_name='osm2pgsql'"};
257+
util::string_joiner_t joiner{' '};
258+
joiner.add("fallback_application_name='osm2pgsql'");
258259

259260
if (std::strchr(opt.db.c_str(), '=') != nullptr) {
260-
out += " ";
261-
out += opt.db;
262-
return out;
261+
joiner.add(opt.db);
262+
return joiner();
263263
}
264264

265-
out += " client_encoding='UTF8'";
265+
joiner.add("client_encoding='UTF8'");
266266

267267
if (!opt.db.empty()) {
268-
out += " dbname='{}'"_format(opt.db);
268+
joiner.add(fmt::format("dbname='{}'", opt.db));
269269
}
270270
if (!opt.username.empty()) {
271-
out += " user='{}'"_format(opt.username);
271+
joiner.add(fmt::format("user='{}'", opt.username));
272272
}
273273
if (!opt.password.empty()) {
274-
out += " password='{}'"_format(opt.password);
274+
joiner.add(fmt::format("password='{}'", opt.password));
275275
}
276276
if (!opt.host.empty()) {
277-
out += " host='{}'"_format(opt.host);
277+
joiner.add(fmt::format("host='{}'", opt.host));
278278
}
279279
if (!opt.port.empty()) {
280-
out += " port='{}'"_format(opt.port);
280+
joiner.add(fmt::format("port='{}'", opt.port));
281281
}
282282

283-
return out;
283+
return joiner();
284284
}
285285

286286
options_t::options_t()

0 commit comments

Comments
 (0)