1 #include "log/format.hpp"
11 inline namespace literals {
13 format_data operator"" _fmt( const char* it, std::size_t len ) {
14 const auto end = it + len;
15 auto retval = format_data {};
21 if( *it == '0' or !std::isalnum( *it ) ) {
30 if( std::isdigit( *it ) ) {
31 const auto w_end = std::find_if_not( it, end,
33 return std::isdigit( c );
35 retval.width = std::stoul( std::string{it, w_end} );
60 retval.align_right = false;
64 retval.align_right = true;
68 throw std::invalid_argument{"invalid format_data-string"};
74 throw std::invalid_argument{"invalid format_data-string"};
80 } // inline namespace literals
86 std::string to_string( const format::formated_string& arg ) {
87 if( arg.value.size() >= arg.width ) {
91 auto str = std::string {};
92 str.reserve( arg.width );
94 if( arg.align_right ) {
95 str.append( arg.width - arg.value.size(), arg.fill );
96 str.append( arg.value );
98 str.append( arg.value );
99 str.append( arg.width - arg.value.size(), arg.fill );
107 } // namespace logger