Skip to content

Commit 575e96f

Browse files
committed
Do not use deprecated form of fmt::format_to() function
Use the version instead that takes an output iterator.
1 parent 07187e0 commit 575e96f

File tree

3 files changed

+64
-41
lines changed

3 files changed

+64
-41
lines changed

src/db-copy.cpp

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,11 @@ void db_deleter_by_id_t::delete_rows(std::string const &table,
2323
// Add 50 characters for the SQL statement itself.
2424
sql.reserve(m_deletables.size() * 15 + 50);
2525

26-
fmt::format_to(sql, FMT_STRING("DELETE FROM {} WHERE {} IN ("), table,
27-
column);
26+
fmt::format_to(std::back_inserter(sql),
27+
FMT_STRING("DELETE FROM {} WHERE {} IN ("), table, column);
2828

2929
for (auto id : m_deletables) {
30-
format_to(sql, FMT_STRING("{},"), id);
30+
format_to(std::back_inserter(sql), FMT_STRING("{},"), id);
3131
}
3232
sql[sql.size() - 1] = ')';
3333

@@ -48,11 +48,12 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
4848
sql.reserve(m_deletables.size() * 22 + 200);
4949

5050
if (m_has_type) {
51-
fmt::format_to(sql, "DELETE FROM {} p USING (VALUES ", table);
51+
fmt::format_to(std::back_inserter(sql),
52+
"DELETE FROM {} p USING (VALUES ", table);
5253

5354
for (auto const &item : m_deletables) {
54-
fmt::format_to(sql, FMT_STRING("('{}',{}),"), item.osm_type,
55-
item.osm_id);
55+
fmt::format_to(std::back_inserter(sql), FMT_STRING("('{}',{}),"),
56+
item.osm_type, item.osm_id);
5657
}
5758

5859
sql.resize(sql.size() - 1);
@@ -61,16 +62,17 @@ void db_deleter_by_type_and_id_t::delete_rows(std::string const &table,
6162
assert(pos != std::string::npos);
6263
std::string type = column.substr(0, pos);
6364

64-
fmt::format_to(sql,
65+
fmt::format_to(std::back_inserter(sql),
6566
") AS t (osm_type, osm_id) WHERE"
6667
" p.{} = t.osm_type AND p.{} = t.osm_id",
6768
type, column.c_str() + pos + 1);
6869
} else {
69-
fmt::format_to(sql, FMT_STRING("DELETE FROM {} WHERE {} IN ("), table,
70+
fmt::format_to(std::back_inserter(sql),
71+
FMT_STRING("DELETE FROM {} WHERE {} IN ("), table,
7072
column);
7173

7274
for (auto const &item : m_deletables) {
73-
format_to(sql, FMT_STRING("{},"), item.osm_id);
75+
format_to(std::back_inserter(sql), FMT_STRING("{},"), item.osm_id);
7476
}
7577
sql[sql.size() - 1] = ')';
7678
}
@@ -194,9 +196,11 @@ void db_copy_thread_t::thread_t::start_copy(
194196
fmt::memory_buffer sql;
195197
sql.reserve(qname.size() + target->rows.size() + 20);
196198
if (target->rows.empty()) {
197-
fmt::format_to(sql, FMT_STRING("COPY {} FROM STDIN"), qname);
199+
fmt::format_to(std::back_inserter(sql),
200+
FMT_STRING("COPY {} FROM STDIN"), qname);
198201
} else {
199-
fmt::format_to(sql, FMT_STRING("COPY {} ({}) FROM STDIN"), qname,
202+
fmt::format_to(std::back_inserter(sql),
203+
FMT_STRING("COPY {} ({}) FROM STDIN"), qname,
200204
target->rows);
201205
}
202206

src/gazetteer-style.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,27 @@ void db_deleter_place_t::delete_rows(std::string const &table,
3434
// the remainder of the SQL command.
3535
sql.reserve(m_deletables.size() * 43 + 200);
3636

37-
fmt::format_to(sql, "DELETE FROM {} p USING (VALUES ", table);
37+
fmt::format_to(std::back_inserter(sql), "DELETE FROM {} p USING (VALUES ",
38+
table);
3839

3940
for (auto const &item : m_deletables) {
40-
fmt::format_to(sql, "('{}',{},", item.osm_type, item.osm_id);
41+
fmt::format_to(std::back_inserter(sql), "('{}',{},", item.osm_type,
42+
item.osm_id);
4143
if (item.classes.empty()) {
42-
fmt::format_to(sql, "ARRAY[]::text[]),");
44+
fmt::format_to(std::back_inserter(sql), "ARRAY[]::text[]),");
4345
} else {
44-
fmt::format_to(sql, "ARRAY[{}]),", item.classes);
46+
fmt::format_to(std::back_inserter(sql), "ARRAY[{}]),",
47+
item.classes);
4548
}
4649
}
4750

4851
// remove the final comma
4952
sql.resize(sql.size() - 1);
5053

51-
fmt::format_to(sql, ") AS t (osm_type, osm_id, classes) WHERE"
52-
" p.osm_type = t.osm_type AND p.osm_id = t.osm_id"
53-
" AND NOT p.class = ANY(t.classes)");
54+
fmt::format_to(std::back_inserter(sql),
55+
") AS t (osm_type, osm_id, classes) WHERE"
56+
" p.osm_type = t.osm_type AND p.osm_id = t.osm_id"
57+
" AND NOT p.class = ANY(t.classes)");
5458

5559
conn->exec(fmt::to_string(sql));
5660
}
@@ -70,7 +74,8 @@ std::string gazetteer_style_t::class_list() const
7074
fmt::memory_buffer buf;
7175

7276
for (auto const &m : m_main) {
73-
fmt::format_to(buf, FMT_STRING("'{}',"), std::get<0>(m));
77+
fmt::format_to(std::back_inserter(buf), FMT_STRING("'{}',"),
78+
std::get<0>(m));
7479
}
7580

7681
if (buf.size() > 0) {

tests/test-output-gazetteer.cpp

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,14 @@ class node_opl_t
3030
{
3131
std::uniform_real_distribution<double> dist{-90, 89.99};
3232

33-
fmt::format_to(m_opl, "n{} T{} x{} y{}\n", id, tags, 2 * dist(rng),
34-
dist(rng));
33+
fmt::format_to(std::back_inserter(m_opl), "n{} T{} x{} y{}\n", id, tags,
34+
2 * dist(rng), dist(rng));
3535
}
3636

37-
void del(osmid_t id) { fmt::format_to(m_opl, "n{} v2 dD\n", id); }
37+
void del(osmid_t id)
38+
{
39+
fmt::format_to(std::back_inserter(m_opl), "n{} v2 dD\n", id);
40+
}
3841

3942
std::string get_and_clear_opl()
4043
{
@@ -57,13 +60,17 @@ class way_opl_t
5760
osmid_t const first_node = m_current_node_id;
5861
osmid_t const last_node = make_nodes();
5962

60-
fmt::format_to(m_way_opl, "w{} T{} N", id, tags);
63+
fmt::format_to(std::back_inserter(m_way_opl), "w{} T{} N", id, tags);
6164
for (osmid_t i = first_node; i <= last_node; ++i) {
62-
fmt::format_to(m_way_opl, "n{}{}", i, i == last_node ? '\n' : ',');
65+
fmt::format_to(std::back_inserter(m_way_opl), "n{}{}", i,
66+
i == last_node ? '\n' : ',');
6367
}
6468
}
6569

66-
void del(osmid_t id) { fmt::format_to(m_way_opl, "w{} v2 dD\n", id); }
70+
void del(osmid_t id)
71+
{
72+
fmt::format_to(std::back_inserter(m_way_opl), "w{} v2 dD\n", id);
73+
}
6774

6875
std::string get_and_clear_opl()
6976
{
@@ -91,8 +98,8 @@ class way_opl_t
9198

9299
std::uniform_real_distribution<double> diff_dist{-0.01, 0.01};
93100
for (unsigned i = 0; i < num_nodes; ++i) {
94-
fmt::format_to(m_node_opl, "n{} x{} y{}\n", m_current_node_id++, x,
95-
y);
101+
fmt::format_to(std::back_inserter(m_node_opl), "n{} x{} y{}\n",
102+
m_current_node_id++, x, y);
96103
double diffx = 0.0;
97104
double diffy = 0.0;
98105
do {
@@ -120,17 +127,20 @@ class relation_opl_t
120127
osmid_t const last_node = make_nodes();
121128

122129
// create a very simple multipolygon with one closed way
123-
fmt::format_to(m_way_opl, "w{} N", id, tags);
130+
fmt::format_to(std::back_inserter(m_way_opl), "w{} N", id, tags);
124131
for (osmid_t i = first_node; i <= last_node; ++i) {
125-
fmt::format_to(m_way_opl, "n{},", i);
132+
fmt::format_to(std::back_inserter(m_way_opl), "n{},", i);
126133
}
127-
fmt::format_to(m_way_opl, "n{}\n", first_node);
134+
fmt::format_to(std::back_inserter(m_way_opl), "n{}\n", first_node);
128135

129-
fmt::format_to(m_rel_opl, "r{} Ttype=multipolygon,{} Mw{}@\n", id, tags,
130-
id);
136+
fmt::format_to(std::back_inserter(m_rel_opl),
137+
"r{} Ttype=multipolygon,{} Mw{}@\n", id, tags, id);
131138
}
132139

133-
void del(osmid_t id) { fmt::format_to(m_rel_opl, "r{} v2 dD\n", id); }
140+
void del(osmid_t id)
141+
{
142+
fmt::format_to(std::back_inserter(m_rel_opl), "r{} v2 dD\n", id);
143+
}
134144

135145
std::string get_and_clear_opl()
136146
{
@@ -157,14 +167,18 @@ class relation_opl_t
157167

158168
std::uniform_real_distribution<double> diff_dist{0.0000001, 0.01};
159169

160-
fmt::format_to(m_node_opl, "n{} x{} y{}\n", m_current_node_id++,
161-
x - diff_dist(rng), y - diff_dist(rng));
162-
fmt::format_to(m_node_opl, "n{} x{} y{}\n", m_current_node_id++,
163-
x - diff_dist(rng), y + diff_dist(rng));
164-
fmt::format_to(m_node_opl, "n{} x{} y{}\n", m_current_node_id++,
165-
x + diff_dist(rng), y + diff_dist(rng));
166-
fmt::format_to(m_node_opl, "n{} x{} y{}\n", m_current_node_id++,
167-
x + diff_dist(rng), y - diff_dist(rng));
170+
fmt::format_to(std::back_inserter(m_node_opl), "n{} x{} y{}\n",
171+
m_current_node_id++, x - diff_dist(rng),
172+
y - diff_dist(rng));
173+
fmt::format_to(std::back_inserter(m_node_opl), "n{} x{} y{}\n",
174+
m_current_node_id++, x - diff_dist(rng),
175+
y + diff_dist(rng));
176+
fmt::format_to(std::back_inserter(m_node_opl), "n{} x{} y{}\n",
177+
m_current_node_id++, x + diff_dist(rng),
178+
y + diff_dist(rng));
179+
fmt::format_to(std::back_inserter(m_node_opl), "n{} x{} y{}\n",
180+
m_current_node_id++, x + diff_dist(rng),
181+
y - diff_dist(rng));
168182

169183
return m_current_node_id - 1;
170184
}

0 commit comments

Comments
 (0)