size_t QLyXKeySym::getUCSEncoded() const
{
- unsigned short const * ptr = text_.ucs2();
- std::vector<unsigned short> tmp(ptr, ptr + text_.length());
+ if (text_.isEmpty())
+ return 0;
+
+ //unsigned short const * ptr = text_.ucs2();
+ //std::vector<unsigned short> tmp(ptr, ptr + text_.length());
//lyxerr << "Data is " << tmp << endl;
//lyxerr << "Length is " << text_.length() << endl;
- if (text_.isEmpty())
- return 0;
-
//size_t res = utf8_to_ucs4(tmp, tmp.length());
//lyxerr << "Res is " << res << endl;
- return ucs2_to_ucs4(tmp)[0];
+ return ucs2_to_ucs4(text_.ucs2(), text_.length())[0];
}
QString const toqstr(docstring const & str)
{
std::vector<unsigned short> ucs2 =
- ucs4_to_ucs2(str.c_str(), str.length());
+ ucs4_to_ucs2(str.data(), str.length());
ucs2.push_back('\0');
return QString::fromUcs2(&ucs2[0]);
}
docstring const qstring_to_ucs4(QString const & str)
{
unsigned short const * const ucs2 = str.ucs2();
- std::vector<char_type> const ucs4 = ucs2_to_ucs4(
- std::vector<unsigned short>(ucs2, ucs2 + str.length()));
+ std::vector<char_type> const ucs4 = ucs2_to_ucs4(ucs2, str.length());
return docstring(ucs4.begin(), ucs4.end());
}
lyx::docstring const LyXLex::Pimpl::getDocString() const
{
- std::vector<boost::uint32_t> res = utf8_to_ucs4(buff);
- lyx::docstring dstr(res.begin(), res.end());
- return dstr;
+ std::vector<boost::uint32_t> res = utf8_to_ucs4(buff);
+ lyx::docstring dstr(res.begin(), res.end());
+ return dstr;
}
docstring const from_utf8(std::string const & utf8)
{
std::vector<boost::uint32_t> const ucs4 =
- utf8_to_ucs4(std::vector<char>(utf8.begin(), utf8.end()));
+ utf8_to_ucs4(utf8.data(), utf8.size());
return docstring(ucs4.begin(), ucs4.end());
}
std::string const to_utf8(docstring const & ucs4)
{
std::vector<char> const utf8 =
- ucs4_to_utf8(std::vector<boost::uint32_t>(ucs4.begin(), ucs4.end()));
+ ucs4_to_utf8(ucs4.data(), ucs4.size());
return std::string(utf8.begin(), utf8.end());
}
std::vector<boost::uint32_t> utf8_to_ucs4(std::vector<char> const & utf8str)
+{
+ return utf8_to_ucs4(&utf8str[0], utf8str.size());
+}
+
+
+std::vector<boost::uint32_t>
+utf8_to_ucs4(char const * utf8str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, "UTF-8",
- &utf8str[0], utf8str.size());
+ utf8str, ls);
+}
+
+
+boost::uint32_t
+ucs2_to_ucs4(unsigned short c)
+{
+ return ucs2_to_ucs4(&c, 1)[0];
}
std::vector<boost::uint32_t>
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str)
+{
+ return ucs2_to_ucs4(&ucs2str[0], ucs2str.size());
+}
+
+
+std::vector<boost::uint32_t>
+ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
return iconv_convert<boost::uint32_t>(&cd, ucs4_codeset, ucs2_codeset,
- &ucs2str[0], ucs2str.size());
+ ucs2str, ls);
+}
+
+
+unsigned short
+ucs4_to_ucs2(boost::uint32_t c)
+{
+ return ucs4_to_ucs2(&c, 1)[0];
}
}
-unsigned short
-ucs4_to_ucs2(boost::uint32_t c)
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t c)
{
- boost::uint32_t tmp[] = { c, 0 };
- return ucs4_to_ucs2(tmp, 1)[0];
+ static iconv_t cd = (iconv_t)(-1);
+ return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset, &c, 1);
}
-std::vector<char> ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
+std::vector<char>
+ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str)
{
- static iconv_t cd = (iconv_t)(-1);
- return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset,
- &ucs4str[0], ucs4str.size());
+ return ucs4_to_utf8(&ucs4str[0], ucs4str.size());
}
-std::vector<char> ucs4_to_utf8(boost::uint32_t c)
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls)
{
static iconv_t cd = (iconv_t)(-1);
- return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset, &c, 1);
+ return iconv_convert<char>(&cd, "UTF-8", ucs4_codeset,
+ ucs4str, ls);
}
#include <boost/cstdint.hpp>
#include <vector>
+// utf8_to_ucs4
+
+// A single codepoint conversion for utf8_to_ucs4 does not make
+// sense, so that function is left out.
+
std::vector<boost::uint32_t>
utf8_to_ucs4(std::vector<char> const & utf8str);
+std::vector<boost::uint32_t>
+utf8_to_ucs4(char const * utf8str, size_t ls);
+
+// ucs2_to_ucs4
+
+boost::uint32_t
+ucs2_to_ucs4(unsigned short c);
+
std::vector<boost::uint32_t>
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
+std::vector<boost::uint32_t>
+ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
+
+// ucs4_to_ucs2
+
+unsigned short
+ucs4_to_ucs2(boost::uint32_t c);
+
std::vector<unsigned short>
ucs4_to_ucs2(std::vector<boost::uint32_t> const & ucs4str);
std::vector<unsigned short>
ucs4_to_ucs2(boost::uint32_t const * s, size_t ls);
-unsigned short
-ucs4_to_ucs2(boost::uint32_t c);
+// ucs4_to_utf8
+
+std::vector<char>
+ucs4_to_utf8(boost::uint32_t c);
std::vector<char>
ucs4_to_utf8(std::vector<boost::uint32_t> const & ucs4str);
std::vector<char>
-ucs4_to_utf8(boost::uint32_t c);
+ucs4_to_utf8(boost::uint32_t const * ucs4str, size_t ls);
#endif