utils: convert sprint() to format()
sprint() recently became more strict, throwing on sprint("%s", 5). Replace
with the more modern format().
Mechanically converted with https://github.com/avikivity/unsprint.
This commit is contained in:
@@ -74,7 +74,7 @@ public:
|
||||
// This matches Java's UUID.toString() actual implementation. Note that
|
||||
// that method's documentation suggest something completely different!
|
||||
sstring to_sstring() const {
|
||||
return sprint("%08x-%04x-%04x-%04x-%012x",
|
||||
return format("{:08x}-{:04x}-{:04x}-{:04x}-{:012x}",
|
||||
((uint64_t)most_sig_bits >> 32),
|
||||
((uint64_t)most_sig_bits >> 16 & 0xffff),
|
||||
((uint64_t)most_sig_bits & 0xffff),
|
||||
|
||||
@@ -32,14 +32,14 @@ big_decimal::big_decimal(sstring_view text)
|
||||
static const std::regex big_decimal_re("^([\\+\\-]?)([0-9]*)(\\.([0-9]*))?([eE]([\\+\\-]?[0-9]+))?");
|
||||
std::smatch sm;
|
||||
if (!std::regex_match(str, sm, big_decimal_re)) {
|
||||
throw marshal_exception(sprint("big_decimal contains invalid characters: '%s'", str));
|
||||
throw marshal_exception(format("big_decimal contains invalid characters: '{}'", str));
|
||||
}
|
||||
bool negative = sm[1] == "-";
|
||||
auto integer = sm[2].str();
|
||||
auto fraction = sm[4].str();
|
||||
auto exponent = sm[6].str();
|
||||
if (integer.empty() && fraction.empty()) {
|
||||
throw marshal_exception(sprint("big_decimal - both integer and fraction are empty: '%s'", str));
|
||||
throw marshal_exception(format("big_decimal - both integer and fraction are empty: '{}'", str));
|
||||
}
|
||||
integer.append(fraction);
|
||||
unsigned i;
|
||||
|
||||
@@ -67,7 +67,7 @@ namespace bloom_calculations {
|
||||
bloom_specification(int k, int buckets_per_element) : K(k), buckets_per_element(buckets_per_element) { }
|
||||
|
||||
operator sstring() {
|
||||
return sprint("bloom_specification(K=%d, buckets_per_element=%d)", K, buckets_per_element);
|
||||
return format("bloom_specification(K={:d}, buckets_per_element={:d})", K, buckets_per_element);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,7 +117,7 @@ namespace bloom_calculations {
|
||||
}
|
||||
|
||||
if (max_false_pos_prob < probs[max_buckets_per_element][max_k]) {
|
||||
throw exceptions::unsupported_operation_exception(sprint("Unable to satisfy %f with %d buckets per element", max_false_pos_prob, max_buckets_per_element));
|
||||
throw exceptions::unsupported_operation_exception(format("Unable to satisfy {:f} with {:d} buckets per element", max_false_pos_prob, max_buckets_per_element));
|
||||
}
|
||||
|
||||
// First find the minimal required number of buckets:
|
||||
@@ -149,7 +149,7 @@ namespace bloom_calculations {
|
||||
v = v / num_elements;
|
||||
|
||||
if (v < 1.0) {
|
||||
throw exceptions::unsupported_operation_exception(sprint("Cannot compute probabilities for %ld elements.", num_elements));
|
||||
throw exceptions::unsupported_operation_exception(format("Cannot compute probabilities for {:d} elements.", num_elements));
|
||||
}
|
||||
return std::min(probs.size() - 1, size_t(v));
|
||||
}
|
||||
|
||||
@@ -421,13 +421,13 @@ public:
|
||||
s += "-Inf";
|
||||
}
|
||||
} else {
|
||||
s += sprint("%d", bucket_offsets[index - 1] + 1);
|
||||
s += format("{:d}", bucket_offsets[index - 1] + 1);
|
||||
}
|
||||
s += "..";
|
||||
if (index == bucket_offsets.size()) {
|
||||
s += "Inf";
|
||||
} else {
|
||||
s += sprint("%d", bucket_offsets[index]);
|
||||
s += format("{:d}", bucket_offsets[index]);
|
||||
}
|
||||
s += "]";
|
||||
return s;
|
||||
|
||||
@@ -103,7 +103,7 @@ public:
|
||||
// uphold the guarantee to enforce ordered "post" execution
|
||||
// and signalling of all larger elements.
|
||||
if (!_map.empty() && !_map.count(rp) && rp < _map.rbegin()->first) {
|
||||
throw std::invalid_argument(sprint("Attempting to insert key out of order: %s", rp));
|
||||
throw std::invalid_argument(format("Attempting to insert key out of order: {}", rp));
|
||||
}
|
||||
|
||||
_gate.enter();
|
||||
|
||||
@@ -290,7 +290,7 @@ public:
|
||||
struct default_exception_thrower {
|
||||
[[noreturn]] [[gnu::cold]]
|
||||
static void throw_out_of_range(size_t attempted_read, size_t actual_left) {
|
||||
throw std::out_of_range(sprint("attempted to read %d bytes from a %d byte buffer", attempted_read, actual_left));
|
||||
throw std::out_of_range(format("attempted to read {:d} bytes from a {:d} byte buffer", attempted_read, actual_left));
|
||||
}
|
||||
};
|
||||
GCC6_CONCEPT(static_assert(fragmented_temporary_buffer_concepts::ExceptionThrower<default_exception_thrower>));
|
||||
|
||||
@@ -32,7 +32,7 @@ filter_ptr i_filter::get_filter(int64_t num_elements, double max_false_pos_proba
|
||||
assert(seastar::thread::running_in_thread());
|
||||
|
||||
if (max_false_pos_probability > 1.0) {
|
||||
throw std::invalid_argument(sprint("Invalid probability %f: must be lower than 1.0", max_false_pos_probability));
|
||||
throw std::invalid_argument(format("Invalid probability {:f}: must be lower than 1.0", max_false_pos_probability));
|
||||
}
|
||||
|
||||
if (max_false_pos_probability == 1.0) {
|
||||
|
||||
@@ -49,7 +49,7 @@ stdx::optional<int_range> intersection(const int_range& a, const int_range& b) {
|
||||
inline
|
||||
int_range make_int_range(int start_inclusive, int end_exclusive) {
|
||||
if (end_exclusive <= start_inclusive) {
|
||||
throw std::runtime_error(sprint("invalid range: [%d, %d)", start_inclusive, end_exclusive));
|
||||
throw std::runtime_error(format("invalid range: [{:d}, {:d})", start_inclusive, end_exclusive));
|
||||
}
|
||||
return int_range({start_inclusive}, {end_exclusive - 1});
|
||||
}
|
||||
|
||||
@@ -1114,13 +1114,13 @@ class region_impl final : public basic_region_impl {
|
||||
|
||||
friend std::ostream& operator<<(std::ostream& out, const object_descriptor& desc) {
|
||||
if (!desc.is_live()) {
|
||||
return out << sprint("{free %d}", desc.dead_size());
|
||||
return out << format("{{free {:d}}}", desc.dead_size());
|
||||
} else {
|
||||
auto m = desc.migrator();
|
||||
auto x = reinterpret_cast<uintptr_t>(&desc) + sizeof(desc);
|
||||
x = align_up(x, m->align());
|
||||
auto obj = reinterpret_cast<const void*>(x);
|
||||
return out << sprint("{migrator=%p, alignment=%d, size=%d}",
|
||||
return out << format("{{migrator={:p}, alignment={:d}, size={:d}}}",
|
||||
(void*)m, m->align(), m->size(obj));
|
||||
}
|
||||
}
|
||||
@@ -1759,7 +1759,7 @@ const eviction_fn& region::evictor() const {
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream& out, const occupancy_stats& stats) {
|
||||
return out << sprint("%.2f%%, %d / %d [B]",
|
||||
return out << format("{:.2f}%, {:d} / {:d} [B]",
|
||||
stats.used_fraction() * 100, stats.used_space(), stats.total_space());
|
||||
}
|
||||
|
||||
@@ -1867,7 +1867,7 @@ struct reclaim_timer {
|
||||
auto bytes_per_second = static_cast<float>(released) / std::chrono::duration_cast<std::chrono::duration<float>>(duration).count();
|
||||
timing_logger.debug("Reclamation cycle took {} us. Reclamation rate = {} MiB/s",
|
||||
std::chrono::duration_cast<std::chrono::duration<double, std::micro>>(duration).count(),
|
||||
sprint("%.3f", bytes_per_second / (1024*1024)));
|
||||
format("{:.3f}", bytes_per_second / (1024*1024)));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -55,7 +55,7 @@ UUID::UUID(sstring_view uuid) {
|
||||
boost::erase_all(uuid_string, "-");
|
||||
auto size = uuid_string.size() / 2;
|
||||
if (size != 16) {
|
||||
throw marshal_exception(sprint("UUID string size mismatch: '%s'", uuid));
|
||||
throw marshal_exception(format("UUID string size mismatch: '{}'", uuid));
|
||||
}
|
||||
sstring most = sstring(uuid_string.begin(), uuid_string.begin() + size);
|
||||
sstring least = sstring(uuid_string.begin() + size, uuid_string.end());
|
||||
|
||||
Reference in New Issue
Block a user