// // format.hpp // logger // // Created by Sam Jaffe on 8/21/16. // #pragma once #include #include #include #include #include "logger_fwd.hpp" namespace logging { class format { public: enum class token_id { DATE, PRIORITY, CATEGORY, MESSAGE, STRING, NEWLINE }; using generator = std::function; private: static format parse_format_string(std::string const &); std::vector gen; }; inline void format_msg( std::stringstream & msg, std::string const & interp, size_t pos) { msg << interp.substr(pos); } struct format_point_t { size_t start; size_t end; }; format_point_t get_next_format_specifier( std::string const & interp, size_t pos ); template inline void format_msg( std::stringstream & msg, std::string const & interp, size_t pos, Arg0 && arg0, Args && ...args ) { format_point_t next = get_next_format_specifier( interp, pos ); msg << interp.substr(pos, next.start) << arg0; if ( next.start == std::string::npos ) return; // throw? format_msg( msg, interp, next.end, std::forward(args)... ); } template inline std::string format_msg( std::string const & interp, Args && ...args ) { std::stringstream msg; format_msg( msg, interp, 0, std::forward(args)... ); return msg.str(); } }