diff --git a/src/utils/microfmt.hpp b/src/utils/microfmt.hpp index 4386b03..b9d7f4c 100644 --- a/src/utils/microfmt.hpp +++ b/src/utils/microfmt.hpp @@ -196,7 +196,7 @@ namespace microfmt { } }; - inline int parse_int(std::string::const_iterator begin, std::string::const_iterator end) { + inline int parse_int(const char* begin, const char* end) { int x = 0; for(auto it = begin; it != end; it++) { MICROFMT_ASSERT(isdigit(*it)); @@ -207,12 +207,12 @@ namespace microfmt { } template - std::string format(const std::string& format_string, std::array args) { + std::string format(const char* fmt_begin, const char* fmt_end, std::array args) { std::string str; std::size_t arg_i = 0; - auto it = format_string.begin(); + auto it = fmt_begin; auto peek = [&] (std::size_t dist = 1) -> char { // 0 on failure - if(it != format_string.end()) { + if(it != fmt_end) { return *(it + dist); } else { return 0; @@ -220,7 +220,7 @@ namespace microfmt { }; auto read_number = [&] () -> int { // -1 on failure auto scan = it; - while(scan != format_string.end() && isdigit(*scan)) { + while(scan != fmt_end && isdigit(*scan)) { scan++; } if(scan != it) { @@ -231,7 +231,7 @@ namespace microfmt { return -1; } }; - while(it != format_string.end()) { + while(it != fmt_end) { if(*it == '{') { if(peek() == '{') { // try to handle escape @@ -240,7 +240,7 @@ namespace microfmt { } else { // parse format string it++; - MICROFMT_ASSERT(it != format_string.end()); + MICROFMT_ASSERT(it != fmt_end); format_options options; // try to parse alignment if(*it == '<' || *it == '>') { @@ -298,18 +298,27 @@ namespace microfmt { } template - std::string format(const std::string& format_string, Args... args) { - return detail::format(format_string, {detail::format_value(args)...}); + #if defined(__cpp_lib_string_view) && __cpp_lib_string_view >= 201606L + std::string format(std::string_view fmt, Args&&... args) { + #else + std::string format(const std::string& fmt, Args&&... args) { + #endif + return detail::format(fmt.begin(), fmt.end(), {detail::format_value(args)...}); } template - void print(const std::string& format_string, Args... args) { - std::cout<(fmt, fmt + std::strlen(fmt), {detail::format_value(args)...}); } - template - void print(std::ostream& ostream, const std::string& format_string, Args... args) { - ostream< + void print(const S& fmt, Args&&... args) { + std::cout< + void print(std::ostream& ostream, const S& fmt, Args&&... args) { + ostream<