Add unicode_cast to wrap utils::X_to_Y() functions
This commit is contained in:
parent
3113763de0
commit
f330080e37
1 changed files with 28 additions and 0 deletions
|
@ -16,6 +16,7 @@
|
|||
#ifndef SERIALIZATION_UNICODE_HPP_INCLUDED
|
||||
#define SERIALIZATION_UNICODE_HPP_INCLUDED
|
||||
|
||||
#include <boost/static_assert.hpp>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <SDL_types.h>
|
||||
|
@ -131,4 +132,31 @@ namespace utils {
|
|||
|
||||
} // end namespace utils
|
||||
|
||||
template <typename To, typename From> inline
|
||||
To unicode_cast(const From &) {
|
||||
BOOST_STATIC_ASSERT_MSG(sizeof(To) == 0, "Invalid types for unicode_cast");
|
||||
return To();
|
||||
}
|
||||
|
||||
template <> inline
|
||||
utf8::string unicode_cast<utf8::string, ucs4::string>(const ucs4::string &in) {
|
||||
return utils::ucs4string_to_string(in);
|
||||
}
|
||||
|
||||
template <> inline
|
||||
ucs4::string unicode_cast<ucs4::string, utf8::string>(const utf8::string &in) {
|
||||
return utils::string_to_ucs4string(in);
|
||||
}
|
||||
|
||||
template <> inline
|
||||
utf16::string unicode_cast<utf16::string, ucs4::string>(const ucs4::string &in) {
|
||||
return utils::ucs4string_to_utf16string(in);
|
||||
}
|
||||
|
||||
template <> inline
|
||||
utf16::string unicode_cast<utf16::string, utf8::string>(const utf8::string &in) {
|
||||
const ucs4::string u4str = utils::string_to_ucs4string(in); //unicode_cast<ucs4::string>(in);
|
||||
return utils::ucs4string_to_utf16string(u4str); //unicode_cast<utf16::string>(u4str);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue