format: fix error reporting with wide strings
This commit is contained in:
@@ -29,9 +29,12 @@ template <typename CharT> using string = std::basic_string<CharT>;
|
||||
template <typename CharT> using iterator = typename std::basic_string<CharT>::const_iterator;
|
||||
template <typename CharT> using expressions = std::vector<Format::Expression<CharT>>;
|
||||
|
||||
std::string invalidCharacter(char c)
|
||||
template <typename CharT>
|
||||
std::string invalidCharacter(CharT c)
|
||||
{
|
||||
return "invalid character '" + boost::lexical_cast<std::string>(c) + "'";
|
||||
return "invalid character '"
|
||||
+ convertString<char, CharT>::apply(boost::lexical_cast<string<CharT>>(c))
|
||||
+ "'";
|
||||
}
|
||||
|
||||
template <typename CharT>
|
||||
|
||||
18
src/format.h
18
src/format.h
@@ -21,12 +21,12 @@
|
||||
#ifndef NCMPCPP_HAVE_FORMAT_H
|
||||
#define NCMPCPP_HAVE_FORMAT_H
|
||||
|
||||
#include <boost/locale/encoding_utf.hpp>
|
||||
#include <boost/variant.hpp>
|
||||
|
||||
#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<bool>
|
||||
StringT tags;
|
||||
if (m_song != nullptr)
|
||||
{
|
||||
tags = convertString<std::is_same<char, CharT>::value, std::string>::apply(
|
||||
tags = convertString<CharT, char>::apply(
|
||||
m_song->getTags(st.function())
|
||||
);
|
||||
}
|
||||
@@ -177,20 +177,6 @@ struct Printer: boost::static_visitor<bool>
|
||||
}
|
||||
|
||||
private:
|
||||
// convert string to appropriate type
|
||||
template <bool AreSame, typename ValueT>
|
||||
struct convertString {
|
||||
static const StringT &apply(const ValueT &s) {
|
||||
return s;
|
||||
}
|
||||
};
|
||||
template <typename ValueT>
|
||||
struct convertString<false, ValueT> {
|
||||
static StringT apply(const ValueT &s) {
|
||||
return boost::locale::conv::utf_to_utf<CharT>(s);
|
||||
}
|
||||
};
|
||||
|
||||
// generic version for streams (buffers, menus)
|
||||
template <typename ValueT, typename OutputStreamT>
|
||||
struct output_ {
|
||||
|
||||
@@ -21,6 +21,7 @@
|
||||
#ifndef NCMPCPP_UTILITY_FUNCTIONAL_H
|
||||
#define NCMPCPP_UTILITY_FUNCTIONAL_H
|
||||
|
||||
#include <boost/locale/encoding_utf.hpp>
|
||||
#include <utility>
|
||||
|
||||
// identity function object
|
||||
@@ -34,4 +35,23 @@ struct id_
|
||||
}
|
||||
};
|
||||
|
||||
// convert string to appropriate type
|
||||
template <typename TargetT, typename SourceT>
|
||||
struct convertString
|
||||
{
|
||||
static std::basic_string<TargetT> apply(const std::basic_string<SourceT> &s)
|
||||
{
|
||||
return boost::locale::conv::utf_to_utf<TargetT>(s);
|
||||
}
|
||||
};
|
||||
template <typename TargetT>
|
||||
struct convertString<TargetT, TargetT>
|
||||
{
|
||||
static const std::basic_string<TargetT> &apply(const std::basic_string<TargetT> &s)
|
||||
{
|
||||
return s;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // NCMPCPP_UTILITY_FUNCTIONAL_H
|
||||
|
||||
Reference in New Issue
Block a user