From 07a2e0b55a86eca3c50d7492b38ca49152e68d33 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 22 Jan 2015 02:45:50 +0300 Subject: [PATCH] fmt::format fixed --- Utilities/StrFmt.cpp | 4 +- Utilities/StrFmt.h | 90 ++++++++------------------------------------ 2 files changed, 17 insertions(+), 77 deletions(-) diff --git a/Utilities/StrFmt.cpp b/Utilities/StrFmt.cpp index 4c8c43cdf2..0b8410e2f4 100644 --- a/Utilities/StrFmt.cpp +++ b/Utilities/StrFmt.cpp @@ -96,9 +96,9 @@ size_t fmt::detail::get_fmt_len(const char* fmt, size_t len) fmt += 2; len -= 2; - if (fmt[1] == '1') + if (fmt[0] == '1') { - assert(len >= 3 && fmt[2] - '0' < 7); + assert(len >= 3 && fmt[1] - '0' < 7); res++; fmt++; len--; diff --git a/Utilities/StrFmt.h b/Utilities/StrFmt.h index 36a1ee4abb..ef8842062a 100644 --- a/Utilities/StrFmt.h +++ b/Utilities/StrFmt.h @@ -435,24 +435,6 @@ namespace fmt } }; - template<> - struct get_fmt - { - static std::string text(const char* fmt, size_t len, char* arg) - { - if (fmt[len - 1] == 's') - { - return arg; - } - else - { - throw "Invalid formatting (char*): " + std::string(fmt, len); - } - - return{}; - } - }; - template<> struct get_fmt { @@ -471,60 +453,6 @@ namespace fmt } }; - //template - //struct get_fmt - //{ - // static std::string text(const char* fmt, size_t len, const char(&arg)[size]) - // { - // if (fmt[len - 1] == 's') - // { - // return std::string(arg, size); - // } - // else - // { - // throw "Invalid formatting (char[size]): " + std::string(fmt, len); - // } - - // return{}; - // } - //}; - - //template - //struct get_fmt - //{ - // static std::string text(const char* fmt, size_t len, const char(&arg)[size]) - // { - // if (fmt[len - 1] == 's') - // { - // return std::string(arg, size); - // } - // else - // { - // throw "Invalid formatting (const char[size]): " + std::string(fmt, len); - // } - - // return{}; - // } - //}; - - template<> - struct get_fmt - { - static std::string text(const char* fmt, size_t len, const std::string& arg) - { - if (fmt[len - 1] == 's') - { - return arg; - } - else - { - throw "Invalid formatting (std::string): " + std::string(fmt, len); - } - - return{}; - } - }; - std::string format(const char* fmt, size_t len); // terminator template @@ -549,6 +477,17 @@ namespace fmt } }; + template<> + struct unveil + { + typedef const char* result_type; + + __forceinline static result_type get_value(const char* arg) + { + return arg; + } + }; + template struct unveil { @@ -563,11 +502,11 @@ namespace fmt template<> struct unveil { - typedef const std::string& result_type; + typedef const char* result_type; __forceinline static result_type get_value(const std::string& arg) { - return arg; + return arg.c_str(); } }; @@ -613,8 +552,9 @@ namespace fmt float (%x, %f) double (%x, %f) bool (%x, %d, %s) - char*, const char*, std::string (%s) + char* (%s) + std::string forced to .c_str() (fmt::unveil) be_t<> of any appropriate type in this list (fmt::unveil) enum of any appropriate type in this list (fmt::unveil)