Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/tscore/bwf_std_format.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,13 @@ bwformat(ts::BufferWriter &w, ts::BWFSpec const &spec, atomic<T> const &v)
{
return ts::bwformat(w, spec, v.load());
}

} // end namespace std

namespace ts
{
BufferWriter &bwformat(BufferWriter &w, BWFSpec const &spec, std::error_code const &ec);

namespace bwf
{
using namespace std::literals; // enable ""sv
Expand Down
18 changes: 18 additions & 0 deletions src/tscore/BufferWriterFormat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,24 @@ bwformat(BufferWriter &w, BWFSpec const &spec, bwf::Errno const &e)
return w;
}

BufferWriter &
bwformat(BufferWriter &w, BWFSpec const &spec, std::error_code const &ec)
{
// This provides convenient safe access to the errno short name array.
static const BWFormat number_fmt{"[{}]"_sv}; // numeric value format.
if (spec.has_numeric_type()) { // if numeric type, print just the numeric
// part.
w.print(number_fmt, ec.value());
} else {
w.write(ec.message());
if (spec._type != 's' && spec._type != 'S') {
w.write(' ');
w.print(number_fmt, ec.value());
}
}
return w;
}

bwf::Date::Date(std::string_view fmt) : _epoch(std::chrono::system_clock::to_time_t(std::chrono::system_clock::now())), _fmt(fmt) {}

BufferWriter &
Expand Down