More unicode work. Fixup some usages.

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@14968 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
Lars Gullik Bjønnes 2006-09-10 18:34:24 +00:00
parent 2a06b31354
commit bb61b2655f
6 changed files with 87 additions and 36 deletions

View File

@ -202,18 +202,18 @@ string QLyXKeySym::getSymbolName() const
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];
}

View File

@ -120,7 +120,7 @@ QString const toqstr(string const & str)
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]);
}
@ -149,8 +149,7 @@ string const fromqstr(QString const & str)
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());
}

View File

@ -73,9 +73,9 @@ string const LyXLex::Pimpl::getString() const
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;
}

View File

@ -41,7 +41,7 @@ docstring const from_ascii(std::string const & ascii)
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());
}
@ -49,7 +49,7 @@ docstring const from_utf8(std::string const & utf8)
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());
}

View File

@ -125,19 +125,47 @@ iconv_convert(iconv_t * cd,
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];
}
@ -157,24 +185,25 @@ ucs4_to_ucs2(boost::uint32_t const * s, size_t ls)
}
unsigned short
ucs4_to_ucs2(boost::uint32_t c)
{
boost::uint32_t tmp[] = { c, 0 };
return ucs4_to_ucs2(tmp, 1)[0];
}
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());
}
std::vector<char> ucs4_to_utf8(boost::uint32_t c)
std::vector<char>
ucs4_to_utf8(boost::uint32_t c)
{
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)
{
return ucs4_to_utf8(&ucs4str[0], ucs4str.size());
}
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,
ucs4str, ls);
}

View File

@ -16,25 +16,48 @@
#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