MCPcopy Create free account
hub / github.com/fmtlib/fmt / format_error_code

Function format_error_code

include/fmt/format-inl.h:92–112  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

90}
91
92FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
93 string_view message) noexcept {
94 // Report error code making sure that the output fits into inline_buffer_size
95 // to avoid dynamic memory allocation and potential bad_alloc.
96 out.try_resize(0);
97 static constexpr char SEP[] = ": ";
98 static constexpr char ERROR_STR[] = "error ";
99 // Subtract 2 to account for terminating null characters in SEP and ERROR_STR.
100 size_t error_code_size = sizeof(SEP) + sizeof(ERROR_STR) - 2;
101 auto abs_value = static_cast<uint32_or_64_or_128_t<int>>(error_code);
102 if (detail::is_negative(error_code)) {
103 abs_value = 0 - abs_value;
104 ++error_code_size;
105 }
106 error_code_size += detail::to_unsigned(detail::count_digits(abs_value));
107 auto it = appender(out);
108 if (message.size() <= inline_buffer_size - error_code_size)
109 fmt::format_to(it, FMT_STRING("{}{}"), message, SEP);
110 fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code);
111 FMT_ASSERT(out.size() <= inline_buffer_size, "");
112}
113
114FMT_FUNC void do_report_error(format_func func, int error_code,
115 const char* message) noexcept {

Callers 3

TESTFunction · 0.85
os.ccFile · 0.85
format-inl.hFile · 0.85

Calls 5

is_negativeFunction · 0.85
to_unsignedFunction · 0.85
count_digitsFunction · 0.85
format_toFunction · 0.70
sizeMethod · 0.45

Tested by 1

TESTFunction · 0.68