}
+/// Is \p c a valid utf16 char?
+inline bool is_utf16(char_type c)
+{
+ // 0xd800 ... 0xdfff is the range of surrogate pairs.
+ return c < 0xd800 || (c > 0xdfff && c < 0x10000);
+}
+
+
/**
* Convert a QChar into a UCS4 character.
* This is a hack (it does only make sense for the common part of the UCS4
*/
inline char_type const qchar_to_ucs4(QChar const & qchar)
{
+ BOOST_ASSERT(is_utf16(static_cast<char_type>(qchar.unicode())));
return static_cast<char_type>(qchar.unicode());
}
*/
inline QChar const ucs4_to_qchar(char_type const ucs4)
{
- // FIXME: The following cast is not a real conversion but it work
- // for the ucs2 subrange of unicode. Instead of an assertion we should
- // return some special characters that indicates that its display is
- // not supported.
- BOOST_ASSERT(ucs4 < 65536);
+ BOOST_ASSERT(is_utf16(ucs4));
return QChar(static_cast<unsigned short>(ucs4));
}
#endif
-/**
- * ucs4_to_qstring - convert a UCS4 encoded char_type * into a QString
- *
- * This is a hack for the painter and font metrics and should not be used
- * elsewhere. Since it uses ucs4_to_qchar it has the same limitations.
- */
-inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
-{
- int i = static_cast<int>(ls);
- s.resize(i);
- for (; --i >= 0;)
- s[i] = ucs4_to_qchar(str[i]);
-}
-
-
/**
* qstring_to_ucs4 - convert a QString into a UCS4 encoded docstring
*