Skip to content

Commit 3b1d9e1

Browse files
committed
Convert all format strings to new specification
1 parent 7fe571a commit 3b1d9e1

39 files changed

+321
-266
lines changed

bench/main.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ class SilentReporter final : public Catch::StreamingReporterBase<SilentReporter>
5757
void testCaseStarting(const Catch::TestCaseInfo &info) override
5858
{
5959
stream << fly::Styler(fly::Style::Bold, fly::Color::Cyan)
60-
<< fly::String::format("[============ %s ============]", info.name) << "\n\n";
60+
<< fly::String::format("[============ {} ============]", info.name) << "\n\n";
6161
}
6262
};
6363

fly/coders/coder.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace {
2727
const auto ratio = (static_cast<double>(decoded_size) - encoded_size) / decoded_size;
2828

2929
LOGD(
30-
"Encoded %u bytes to %u bytes (%f%%) in %f seconds",
30+
"Encoded {} bytes to {} bytes ({:.2f}%) in {:.2f} seconds",
3131
decoded_size,
3232
encoded_size,
3333
ratio * 100.0,
@@ -43,7 +43,7 @@ namespace {
4343
const auto end = std::chrono::system_clock::now();
4444

4545
LOGD(
46-
"Decoded %u bytes to %u bytes in %f seconds",
46+
"Decoded {} bytes to {} bytes in {:.2f} seconds",
4747
encoded_size,
4848
decoded_size,
4949
std::chrono::duration<double>(end - start).count());

fly/coders/huffman/huffman_decoder.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,14 @@ bool HuffmanDecoder::decode_binary(BitStreamReader &encoded, std::ostream &decod
4747
if (!decode_codes(encoded, max_code_length))
4848
{
4949
LOGW(
50-
"Error decoding codes from stream (maximum code length = %u)",
50+
"Error decoding codes from stream (maximum code length = {})",
5151
static_cast<std::uint32_t>(m_max_code_length));
5252
return false;
5353
}
5454
else if (!decode_symbols(encoded, max_code_length, chunk_size, decoded))
5555
{
5656
LOGW(
57-
"Error decoding %u symbols from stream (fully consumed = %d)",
57+
"Error decoding {} symbols from stream (fully consumed = {})",
5858
chunk_size,
5959
encoded.fully_consumed());
6060
return false;
@@ -82,7 +82,7 @@ bool HuffmanDecoder::decode_header(BitStreamReader &encoded, std::uint32_t &chun
8282
return decode_header_version1(encoded, chunk_size);
8383

8484
default:
85-
LOGW("Decoded invalid Huffman version %u", static_cast<std::uint32_t>(huffman_version));
85+
LOGW("Decoded invalid Huffman version {}", static_cast<std::uint32_t>(huffman_version));
8686
break;
8787
}
8888

@@ -102,7 +102,7 @@ bool HuffmanDecoder::decode_header_version1(BitStreamReader &encoded, std::uint3
102102
}
103103
else if (encoded_chunk_size_kb == 0)
104104
{
105-
LOGW("Decoded invalid chunk size %u", static_cast<std::uint32_t>(encoded_chunk_size_kb));
105+
LOGW("Decoded invalid chunk size {}", static_cast<std::uint32_t>(encoded_chunk_size_kb));
106106
return false;
107107
}
108108

@@ -119,7 +119,7 @@ bool HuffmanDecoder::decode_header_version1(BitStreamReader &encoded, std::uint3
119119
(encoded_max_code_length >= std::numeric_limits<code_type>::digits))
120120
{
121121
LOGW(
122-
"Decoded invalid maximum code length %u",
122+
"Decoded invalid maximum code length {}",
123123
static_cast<std::uint32_t>(encoded_max_code_length));
124124
return false;
125125
}
@@ -146,7 +146,7 @@ bool HuffmanDecoder::decode_codes(BitStreamReader &encoded, length_type &max_cod
146146
else if ((counts_size == 0) || (counts_size > (m_max_code_length + 1)))
147147
{
148148
LOGW(
149-
"Decoded invalid number of code length counts %u",
149+
"Decoded invalid number of code length counts {}",
150150
static_cast<std::uint32_t>(counts_size));
151151
return false;
152152
}
@@ -177,7 +177,7 @@ bool HuffmanDecoder::decode_codes(BitStreamReader &encoded, length_type &max_cod
177177
if (!encoded.read_byte(symbol))
178178
{
179179
LOGW(
180-
"Could not decode symbol of length %u bits",
180+
"Could not decode symbol of length {} bits",
181181
static_cast<std::uint32_t>(length));
182182
return false;
183183
}
@@ -197,7 +197,7 @@ bool HuffmanDecoder::decode_codes(BitStreamReader &encoded, length_type &max_cod
197197

198198
if (m_huffman_codes_size == m_huffman_codes.size())
199199
{
200-
LOGW("Exceeded maximum number of codes: %u", m_huffman_codes_size);
200+
LOGW("Exceeded maximum number of codes: {}", m_huffman_codes_size);
201201
return false;
202202
}
203203

fly/coders/huffman/huffman_encoder.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ bool HuffmanEncoder::encode_binary(std::istream &decoded, BitStreamWriter &encod
3232
if (m_max_code_length >= std::numeric_limits<code_type>::digits)
3333
{
3434
LOGW(
35-
"Maximum Huffman code length %u is too large for code_type",
35+
"Maximum Huffman code length {} is too large for code_type",
3636
static_cast<std::uint32_t>(m_max_code_length));
3737
return false;
3838
}

fly/config/config_manager.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ ConfigManager::ConfigManager(
3030
break;
3131

3232
default:
33-
LOGE("Unrecognized configuration type: %d", static_cast<int>(file_type));
33+
LOGE("Unrecognized configuration type: {}", static_cast<int>(file_type));
3434
break;
3535
}
3636
}

fly/config/config_manager.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ std::shared_ptr<T> ConfigManager::create_config()
137137
}
138138
else
139139
{
140-
LOGW("Could not create configuration for type %s", T::identifier);
140+
LOGW("Could not create configuration for type {}", T::identifier);
141141
}
142142

143143
return config;

fly/logger/detail/console_sink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ bool ConsoleSink::stream(fly::Log &&log)
4747

4848
{
4949
auto styler = color ? fly::Styler(std::move(style), *std::move(color)) : fly::Styler(style);
50-
String::format(*stream, "%s%s %s", styler, fly::System::local_time(), log.m_trace);
50+
String::format(*stream, "{}{} {}", styler, fly::System::local_time(), log.m_trace);
5151
}
5252

5353
*stream << ": " << log.m_message << std::endl;

fly/logger/detail/file_sink.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ bool FileSink::create_log_file()
7575
fly::String::replace_all(time, ":", '-');
7676
fly::String::replace_all(time, " ", '_');
7777

78-
std::string file_name = fly::String::format("Log_%d_%s_%s.log", ++m_log_index, time, random);
78+
std::string file_name = fly::String::format("Log_{}_{}_{}.log", ++m_log_index, time, random);
7979
m_log_file = m_log_directory / std::move(file_name);
8080

8181
m_log_stream.open(m_log_file, std::ios::out);

fly/logger/detail/registry.cpp

+3-4
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,12 @@ std::shared_ptr<fly::Logger> Registry::get_logger(const std::string &name)
9191
{
9292
std::lock_guard<std::mutex> lock(m_registry_mutex);
9393

94-
auto it = m_registry.find(name);
95-
if (it == m_registry.end())
94+
if (auto it = m_registry.find(name); it != m_registry.end())
9695
{
97-
return nullptr;
96+
return it->second.lock();
9897
}
9998

100-
return it->second.lock();
99+
return nullptr;
101100
}
102101

103102
} // namespace fly::detail

fly/logger/logger.hpp

+74-30
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
* format that string. For example:
2020
*
2121
* LOGD("This is a message");
22-
* LOGD("This is message number %d", 10);
22+
* LOGD("This is message number {:d}", 10);
2323
*/
2424
#define LOGD(...) \
2525
do \
@@ -36,7 +36,7 @@
3636
* format that string. For example:
3737
*
3838
* LOGI("This is a message");
39-
* LOGI("This is message number %d", 10);
39+
* LOGI("This is message number {:d}", 10);
4040
*/
4141
#define LOGI(...) \
4242
do \
@@ -53,7 +53,7 @@
5353
* format that string. For example:
5454
*
5555
* LOGW("This is a message");
56-
* LOGW("This is message number %d", 10);
56+
* LOGW("This is message number {:d}", 10);
5757
*/
5858
#define LOGW(...) \
5959
do \
@@ -71,14 +71,14 @@
7171
* format that string. For example:
7272
*
7373
* LOGS("This is a message");
74-
* LOGS("This is message number %d", 10);
74+
* LOGS("This is message number {:d}", 10);
7575
*/
7676
#define LOGS(...) \
7777
do \
7878
{ \
7979
fly::Logger::get_default_logger()->warn( \
8080
{__FILE__, __FUNCTION__, static_cast<std::uint32_t>(__LINE__)}, \
81-
FLY_FORMAT_STRING(__VA_ARGS__) ": %s" FLY_FORMAT_ARGS(__VA_ARGS__), \
81+
FLY_FORMAT_STRING(__VA_ARGS__) ": {}" FLY_FORMAT_ARGS(__VA_ARGS__), \
8282
fly::System::get_error_string()); \
8383
} while (0)
8484

@@ -89,7 +89,7 @@
8989
* format that string. For example:
9090
*
9191
* LOGE("This is a message");
92-
* LOGE("This is message number %d", 10);
92+
* LOGE("This is message number {:d}", 10);
9393
*/
9494
#define LOGE(...) \
9595
do \
@@ -276,10 +276,14 @@ class Logger : public std::enable_shared_from_this<Logger>
276276
* @param format The format string for the log point.
277277
* @param args The variadic list of arguments to augment the format string with.
278278
*/
279-
template <typename... Args>
280-
void debug(const char *format, const Args &...args)
279+
template <typename... ParameterTypes>
280+
inline void
281+
debug(String::FormatString<ParameterTypes...> &&format, ParameterTypes &&...parameters)
281282
{
282-
log(Log::Level::Debug, {}, String::format(format, args...));
283+
debug(
284+
{},
285+
std::forward<String::FormatString<ParameterTypes...>>(format),
286+
std::forward<ParameterTypes>(parameters)...);
283287
}
284288

285289
/**
@@ -291,10 +295,17 @@ class Logger : public std::enable_shared_from_this<Logger>
291295
* @param format The format string for the log point.
292296
* @param args The variadic list of arguments to augment the format string with.
293297
*/
294-
template <typename... Args>
295-
void debug(Log::Trace &&trace, const char *format, const Args &...args)
298+
template <typename... ParameterTypes>
299+
inline void debug(
300+
Log::Trace &&trace,
301+
String::FormatString<ParameterTypes...> &&format,
302+
ParameterTypes &&...parameters)
296303
{
297-
log(Log::Level::Debug, std::move(trace), String::format(format, args...));
304+
log(Log::Level::Debug,
305+
std::move(trace),
306+
String::format(
307+
std::forward<String::FormatString<ParameterTypes...>>(format),
308+
std::forward<ParameterTypes>(parameters)...));
298309
}
299310

300311
/**
@@ -305,10 +316,14 @@ class Logger : public std::enable_shared_from_this<Logger>
305316
* @param format The format string for the log point.
306317
* @param args The variadic list of arguments to augment the format string with.
307318
*/
308-
template <typename... Args>
309-
void info(const char *format, const Args &...args)
319+
template <typename... ParameterTypes>
320+
inline void
321+
info(String::FormatString<ParameterTypes...> &&format, ParameterTypes &&...parameters)
310322
{
311-
log(Log::Level::Info, {}, String::format(format, args...));
323+
info(
324+
{},
325+
std::forward<String::FormatString<ParameterTypes...>>(format),
326+
std::forward<ParameterTypes>(parameters)...);
312327
}
313328

314329
/**
@@ -320,10 +335,17 @@ class Logger : public std::enable_shared_from_this<Logger>
320335
* @param format The format string for the log point.
321336
* @param args The variadic list of arguments to augment the format string with.
322337
*/
323-
template <typename... Args>
324-
void info(Log::Trace &&trace, const char *format, const Args &...args)
338+
template <typename... ParameterTypes>
339+
inline void info(
340+
Log::Trace &&trace,
341+
String::FormatString<ParameterTypes...> &&format,
342+
ParameterTypes &&...parameters)
325343
{
326-
log(Log::Level::Info, std::move(trace), String::format(format, args...));
344+
log(Log::Level::Info,
345+
std::move(trace),
346+
String::format(
347+
std::forward<String::FormatString<ParameterTypes...>>(format),
348+
std::forward<ParameterTypes>(parameters)...));
327349
}
328350

329351
/**
@@ -334,10 +356,14 @@ class Logger : public std::enable_shared_from_this<Logger>
334356
* @param format The format string for the log point.
335357
* @param args The variadic list of arguments to augment the format string with.
336358
*/
337-
template <typename... Args>
338-
void warn(const char *format, const Args &...args)
359+
template <typename... ParameterTypes>
360+
inline void
361+
warn(String::FormatString<ParameterTypes...> &&format, ParameterTypes &&...parameters)
339362
{
340-
log(Log::Level::Warn, {}, String::format(format, args...));
363+
warn(
364+
{},
365+
std::forward<String::FormatString<ParameterTypes...>>(format),
366+
std::forward<ParameterTypes>(parameters)...);
341367
}
342368

343369
/**
@@ -349,10 +375,17 @@ class Logger : public std::enable_shared_from_this<Logger>
349375
* @param format The format string for the log point.
350376
* @param args The variadic list of arguments to augment the format string with.
351377
*/
352-
template <typename... Args>
353-
void warn(Log::Trace &&trace, const char *format, const Args &...args)
378+
template <typename... ParameterTypes>
379+
inline void warn(
380+
Log::Trace &&trace,
381+
String::FormatString<ParameterTypes...> &&format,
382+
ParameterTypes &&...parameters)
354383
{
355-
log(Log::Level::Warn, std::move(trace), String::format(format, args...));
384+
log(Log::Level::Warn,
385+
std::move(trace),
386+
String::format(
387+
std::forward<String::FormatString<ParameterTypes...>>(format),
388+
std::forward<ParameterTypes>(parameters)...));
356389
}
357390

358391
/**
@@ -363,10 +396,14 @@ class Logger : public std::enable_shared_from_this<Logger>
363396
* @param format The format string for the log point.
364397
* @param args The variadic list of arguments to augment the format string with.
365398
*/
366-
template <typename... Args>
367-
void error(const char *format, const Args &...args)
399+
template <typename... ParameterTypes>
400+
inline void
401+
error(String::FormatString<ParameterTypes...> &&format, ParameterTypes &&...parameters)
368402
{
369-
log(Log::Level::Error, {}, String::format(format, args...));
403+
error(
404+
{},
405+
std::forward<String::FormatString<ParameterTypes...>>(format),
406+
std::forward<ParameterTypes>(parameters)...);
370407
}
371408

372409
/**
@@ -378,10 +415,17 @@ class Logger : public std::enable_shared_from_this<Logger>
378415
* @param format The format string for the log point.
379416
* @param args The variadic list of arguments to augment the format string with.
380417
*/
381-
template <typename... Args>
382-
void error(Log::Trace &&trace, const char *format, const Args &...args)
418+
template <typename... ParameterTypes>
419+
inline void error(
420+
Log::Trace &&trace,
421+
String::FormatString<ParameterTypes...> &&format,
422+
ParameterTypes &&...parameters)
383423
{
384-
log(Log::Level::Error, std::move(trace), String::format(format, args...));
424+
log(Log::Level::Error,
425+
std::move(trace),
426+
String::format(
427+
std::forward<String::FormatString<ParameterTypes...>>(format),
428+
std::forward<ParameterTypes>(parameters)...));
385429
}
386430

387431
private:

0 commit comments

Comments
 (0)