add utf16string_to_ucs4string
This commit is contained in:
parent
41fa779b08
commit
692f9e2d4a
2 changed files with 28 additions and 0 deletions
|
@ -118,6 +118,28 @@ ucs4::string string_to_ucs4string(const std::string &src)
|
|||
return res;
|
||||
}
|
||||
|
||||
ucs4::string utf16string_to_ucs4string(const utf16::string & src)
|
||||
{
|
||||
ucs4::string res;
|
||||
|
||||
try {
|
||||
utf16::iterator i1(src);
|
||||
const utf16::iterator i2(utf16::iterator::end(src));
|
||||
|
||||
// Equivalent to res.insert(res.end(),i1,i2) which doesn't work on VC++6.
|
||||
while(i1 != i2) {
|
||||
res.push_back(*i1);
|
||||
++i1;
|
||||
}
|
||||
}
|
||||
catch(utf8::invalid_utf8_exception&) {
|
||||
ERR_GENERAL << "Invalid UTF-16 string" << std::endl;
|
||||
return res;
|
||||
}
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
utf16::string ucs4string_to_utf16string(const ucs4::string &src)
|
||||
{
|
||||
utf16::string res;
|
||||
|
|
|
@ -107,6 +107,7 @@ namespace implementation {
|
|||
std::string ucs4string_to_string(const ucs4::string &);
|
||||
ucs4::string string_to_ucs4string(const std::string &);
|
||||
std::string ucs4char_to_string(const ucs4::char_t);
|
||||
ucs4::string utf16string_to_ucs4string(const utf16::string &);
|
||||
utf16::string ucs4string_to_utf16string(const ucs4::string &);
|
||||
} // end namespace implementation
|
||||
|
||||
|
@ -142,4 +143,9 @@ utf16::string unicode_cast<utf16::string, utf8::string>(const utf8::string &in)
|
|||
return unicode_cast<utf16::string>(u4str);
|
||||
}
|
||||
|
||||
template <> inline
|
||||
ucs4::string unicode_cast<ucs4::string, utf16::string>(const utf16::string &in) {
|
||||
return implementation::utf16string_to_ucs4string(in);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue