diff --git a/format.cpp b/format.cpp index 284e3d3a..78104472 100644 --- a/format.cpp +++ b/format.cpp @@ -17,10 +17,3 @@ #include "format.hpp" #include - - -//std::string -//util::format (std::string &&fmt) -//{ -// return std::move (fmt); -//} diff --git a/format.hpp b/format.hpp index 31f6ddff..3947a18e 100644 --- a/format.hpp +++ b/format.hpp @@ -11,7 +11,7 @@ * See the License for the specific language governing permissions and * limitations under the License. * - * Copyright 2015 Danny Robson + * Copyright 2015-2016 Danny Robson */ #ifndef __UTIL_FORMAT_HPP @@ -37,6 +37,19 @@ namespace util { class format_error : public error { using error::error; }; + template + class invalid_specifier : public format_error { + public: + using value_type = ValueT; + + invalid_specifier (char specifier); + + char specifier (void) const; + + private: + char m_specifier; + }; + // missing format specifier class missing_error : public error { using error::error; }; diff --git a/format.ipp b/format.ipp index ea2a1411..7e6afcc4 100644 --- a/format.ipp +++ b/format.ipp @@ -165,7 +165,7 @@ namespace util { throw util::format::format_error ("missing format specifier"); if (!is_valid_specifier::type> (&*spec)) - throw util::format::format_error ("invalid/unhandled format specifier"); + throw util::format::invalid_specifier (*spec); if (*spec == 'x') { dest << std::hex << val << std::dec; @@ -194,4 +194,25 @@ namespace util { return out.str (); } } + + + /////////////////////////////////////////////////////////////////////////// + // TODO: we'd like to use typeid here for type naming, but we don't allow + // RTTI. revisit this when introspection is more advanced. + template + format::invalid_specifier::invalid_specifier (char _specifier): + format_error ( + format::render ("invalid specifier '%c' for type '%s'", + _specifier, + "unimplemented") + ), + m_specifier (_specifier) + { ; } + + + //------------------------------------------------------------------------- + template + char + format::invalid_specifier::specifier (void) const + { return m_specifier; } } diff --git a/test/format.cpp b/test/format.cpp index a3c0cb37..c3aa6fb1 100644 --- a/test/format.cpp +++ b/test/format.cpp @@ -17,7 +17,7 @@ main (void) util::format::render ("%s"); }, "missing value"); - tap.expect_throw ([] (void) { + tap.expect_throw> ([] (void) { util::format::render ("%<", 42); }, "invalid specifier");