From 50bfec96464b22e48a4fa237a54f54a17bd767ad Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Tue, 11 Nov 2014 00:59:24 +0100 Subject: [PATCH] format: fix error reporting with wide strings --- src/format.cpp | 7 +++++-- src/format.h | 18 ++---------------- src/utility/functional.h | 20 ++++++++++++++++++++ 3 files changed, 27 insertions(+), 18 deletions(-) diff --git a/src/format.cpp b/src/format.cpp index 20fa6d7a..a36fd845 100644 --- a/src/format.cpp +++ b/src/format.cpp @@ -29,9 +29,12 @@ template using string = std::basic_string; template using iterator = typename std::basic_string::const_iterator; template using expressions = std::vector>; -std::string invalidCharacter(char c) +template +std::string invalidCharacter(CharT c) { - return "invalid character '" + boost::lexical_cast(c) + "'"; + return "invalid character '" + + convertString::apply(boost::lexical_cast>(c)) + + "'"; } template diff --git a/src/format.h b/src/format.h index 282c7257..30af58f6 100644 --- a/src/format.h +++ b/src/format.h @@ -21,12 +21,12 @@ #ifndef NCMPCPP_HAVE_FORMAT_H #define NCMPCPP_HAVE_FORMAT_H -#include #include #include "menu.h" #include "song.h" #include "strbuffer.h" +#include "utility/functional.h" #include "utility/wide_string.h" namespace Format { @@ -125,7 +125,7 @@ struct Printer: boost::static_visitor StringT tags; if (m_song != nullptr) { - tags = convertString::value, std::string>::apply( + tags = convertString::apply( m_song->getTags(st.function()) ); } @@ -177,20 +177,6 @@ struct Printer: boost::static_visitor } private: - // convert string to appropriate type - template - struct convertString { - static const StringT &apply(const ValueT &s) { - return s; - } - }; - template - struct convertString { - static StringT apply(const ValueT &s) { - return boost::locale::conv::utf_to_utf(s); - } - }; - // generic version for streams (buffers, menus) template struct output_ { diff --git a/src/utility/functional.h b/src/utility/functional.h index 7b422cc1..1b96ea2c 100644 --- a/src/utility/functional.h +++ b/src/utility/functional.h @@ -21,6 +21,7 @@ #ifndef NCMPCPP_UTILITY_FUNCTIONAL_H #define NCMPCPP_UTILITY_FUNCTIONAL_H +#include #include // identity function object @@ -34,4 +35,23 @@ struct id_ } }; +// convert string to appropriate type +template +struct convertString +{ + static std::basic_string apply(const std::basic_string &s) + { + return boost::locale::conv::utf_to_utf(s); + } +}; +template +struct convertString +{ + static const std::basic_string &apply(const std::basic_string &s) + { + return s; + } +}; + + #endif // NCMPCPP_UTILITY_FUNCTIONAL_H