mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-26 19:25:39 +00:00
Make string conversion work with non-ucs2-characters if using qt 4.2
* src/frontends/qt4/qt_helpers.[Ch] (toqstr): Use QString::fromUcs4 if the qt version is at least 4.2. (qstring_to_ucs4): Use QString::toUcs4 if the qt version is at least 4.2 (ucs4_to_qstring): Delete to avoid confusion, since it was only used in one place * src/frontends/qt4/panelstack.C (PanelStack::addCategory): Use toqstr instead of ucs4_to_qstring * src/support/unicode.[Ch] (ucs2_to_ucs4): Replace with utf16_to_ucs4 (ucs4_to_ucs2): Replace with ucs4_to_utf16 git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@16169 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
parent
015abe1a5a
commit
c4320d24cd
@ -60,8 +60,7 @@ void PanelStack::addCategory(docstring const & n, docstring const & parent)
|
|||||||
{
|
{
|
||||||
QTreeWidgetItem * item;
|
QTreeWidgetItem * item;
|
||||||
|
|
||||||
QString name;
|
QString const name(toqstr(n));
|
||||||
lyx::ucs4_to_qstring(n, name);
|
|
||||||
|
|
||||||
lyxerr[Debug::GUI] << "addCategory n= " << lyx::to_utf8(n) << " parent= " << endl;
|
lyxerr[Debug::GUI] << "addCategory n= " << lyx::to_utf8(n) << " parent= " << endl;
|
||||||
|
|
||||||
|
@ -111,30 +111,33 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void ucs4_to_qstring(lyx::docstring const & str, QString & s)
|
#if QT_VERSION < 0x040200
|
||||||
|
// We use QString::fromUcs4 in Qt 4.2 and higher
|
||||||
|
QString const toqstr(docstring const & str)
|
||||||
{
|
{
|
||||||
|
QString s;
|
||||||
int i = static_cast<int>(str.size());
|
int i = static_cast<int>(str.size());
|
||||||
s.resize(i);
|
s.resize(i);
|
||||||
for (; --i >= 0;)
|
for (; --i >= 0;)
|
||||||
s[i] = ucs4_to_qchar(str[i]);
|
s[i] = ucs4_to_qchar(str[i]);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
QString const toqstr(docstring const & ucs4)
|
|
||||||
{
|
|
||||||
QString s;
|
|
||||||
ucs4_to_qstring(ucs4, s);
|
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
docstring const qstring_to_ucs4(QString const & qstr)
|
docstring const qstring_to_ucs4(QString const & qstr)
|
||||||
{
|
{
|
||||||
|
#if QT_VERSION >= 0x040200
|
||||||
|
QVector<uint> const ucs4 = qstr.toUcs4();
|
||||||
|
return docstring(ucs4.begin(), ucs4.end());
|
||||||
|
#else
|
||||||
|
// This does not properly convert surrogate pairs
|
||||||
int const ls = qstr.size();
|
int const ls = qstr.size();
|
||||||
docstring ucs4;
|
docstring ucs4;
|
||||||
for (int i = 0; i < ls; ++i)
|
for (int i = 0; i < ls; ++i)
|
||||||
ucs4 += static_cast<char_type>(qstr[i].unicode());
|
ucs4 += static_cast<char_type>(qstr[i].unicode());
|
||||||
return ucs4;
|
return ucs4;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -87,9 +87,18 @@ inline QChar const ucs4_to_qchar(char_type const ucs4) {
|
|||||||
return QChar(static_cast<unsigned short>(ucs4));
|
return QChar(static_cast<unsigned short>(ucs4));
|
||||||
}
|
}
|
||||||
|
|
||||||
QString const toqstr(docstring const & ucs4);
|
|
||||||
|
|
||||||
void ucs4_to_qstring(docstring const & str, QString & s);
|
#if QT_VERSION >= 0x040200
|
||||||
|
inline QString const toqstr(docstring const & ucs4)
|
||||||
|
{
|
||||||
|
// If possible we let qt do the work, since this version does not
|
||||||
|
// need to be superfast.
|
||||||
|
return QString::fromUcs4(reinterpret_cast<uint const *>(ucs4.data()), ucs4.length());
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
QString const toqstr(docstring const & ucs4);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
|
inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s)
|
||||||
{
|
{
|
||||||
|
@ -24,14 +24,23 @@
|
|||||||
|
|
||||||
using std::endl;
|
using std::endl;
|
||||||
|
|
||||||
|
namespace {
|
||||||
|
|
||||||
|
#ifdef WORDS_BIGENDIAN
|
||||||
|
char const * utf16_codeset = "UTF16-BE";
|
||||||
|
#else
|
||||||
|
char const * utf16_codeset = "UTF16-LE";
|
||||||
|
#endif
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
namespace lyx {
|
namespace lyx {
|
||||||
|
|
||||||
#ifdef WORDS_BIGENDIAN
|
#ifdef WORDS_BIGENDIAN
|
||||||
char const * ucs4_codeset = "UCS-4BE";
|
char const * ucs4_codeset = "UCS-4BE";
|
||||||
char const * ucs2_codeset = "UCS-2BE";
|
|
||||||
#else
|
#else
|
||||||
char const * ucs4_codeset = "UCS-4LE";
|
char const * ucs4_codeset = "UCS-4LE";
|
||||||
char const * ucs2_codeset = "UCS-2LE";
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static const iconv_t invalid_cd = (iconv_t)(-1);
|
static const iconv_t invalid_cd = (iconv_t)(-1);
|
||||||
@ -219,52 +228,18 @@ utf8_to_ucs4(char const * utf8str, size_t ls)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
lyx::char_type
|
std::vector<char_type>
|
||||||
ucs2_to_ucs4(unsigned short c)
|
utf16_to_ucs4(unsigned short const * s, size_t ls)
|
||||||
{
|
{
|
||||||
return ucs2_to_ucs4(&c, 1)[0];
|
static IconvProcessor processor(ucs4_codeset, utf16_codeset);
|
||||||
}
|
return iconv_convert<char_type>(processor, s, ls);
|
||||||
|
|
||||||
|
|
||||||
std::vector<lyx::char_type>
|
|
||||||
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str)
|
|
||||||
{
|
|
||||||
if (ucs2str.empty())
|
|
||||||
return std::vector<lyx::char_type>();
|
|
||||||
|
|
||||||
return ucs2_to_ucs4(&ucs2str[0], ucs2str.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<lyx::char_type>
|
|
||||||
ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls)
|
|
||||||
{
|
|
||||||
static IconvProcessor processor(ucs4_codeset, ucs2_codeset);
|
|
||||||
return iconv_convert<lyx::char_type>(processor, ucs2str, ls);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
unsigned short
|
|
||||||
ucs4_to_ucs2(lyx::char_type c)
|
|
||||||
{
|
|
||||||
return ucs4_to_ucs2(&c, 1)[0];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
std::vector<unsigned short>
|
std::vector<unsigned short>
|
||||||
ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str)
|
ucs4_to_utf16(char_type const * s, size_t ls)
|
||||||
{
|
{
|
||||||
if (ucs4str.empty())
|
static IconvProcessor processor(utf16_codeset, ucs4_codeset);
|
||||||
return std::vector<unsigned short>();
|
|
||||||
|
|
||||||
return ucs4_to_ucs2(&ucs4str[0], ucs4str.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
std::vector<unsigned short>
|
|
||||||
ucs4_to_ucs2(lyx::char_type const * s, size_t ls)
|
|
||||||
{
|
|
||||||
static IconvProcessor processor(ucs2_codeset, ucs4_codeset);
|
|
||||||
return iconv_convert<unsigned short>(processor, s, ls);
|
return iconv_convert<unsigned short>(processor, s, ls);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,24 +67,13 @@ std::vector<lyx::char_type> utf8_to_ucs4(std::vector<char> const & utf8str);
|
|||||||
|
|
||||||
std::vector<lyx::char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
|
std::vector<lyx::char_type> utf8_to_ucs4(char const * utf8str, size_t ls);
|
||||||
|
|
||||||
// ucs2_to_ucs4
|
// utf16_to_ucs4
|
||||||
|
|
||||||
lyx::char_type ucs2_to_ucs4(unsigned short c);
|
std::vector<char_type> utf16_to_ucs4(unsigned short const * s, size_t ls);
|
||||||
|
|
||||||
std::vector<lyx::char_type>
|
// ucs4_to_utf16
|
||||||
ucs2_to_ucs4(std::vector<unsigned short> const & ucs2str);
|
|
||||||
|
|
||||||
std::vector<lyx::char_type>
|
std::vector<unsigned short> ucs4_to_utf16(char_type const * s, size_t ls);
|
||||||
ucs2_to_ucs4(unsigned short const * ucs2str, size_t ls);
|
|
||||||
|
|
||||||
// ucs4_to_ucs2
|
|
||||||
|
|
||||||
unsigned short ucs4_to_ucs2(lyx::char_type c);
|
|
||||||
|
|
||||||
std::vector<unsigned short>
|
|
||||||
ucs4_to_ucs2(std::vector<lyx::char_type> const & ucs4str);
|
|
||||||
|
|
||||||
std::vector<unsigned short> ucs4_to_ucs2(lyx::char_type const * s, size_t ls);
|
|
||||||
|
|
||||||
// ucs4_to_utf8
|
// ucs4_to_utf8
|
||||||
|
|
||||||
@ -105,7 +94,6 @@ std::vector<char>
|
|||||||
ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
|
ucs4_to_eightbit(lyx::char_type const * ucs4str, size_t ls, std::string const & encoding);
|
||||||
|
|
||||||
extern char const * ucs4_codeset;
|
extern char const * ucs4_codeset;
|
||||||
extern char const * ucs2_codeset;
|
|
||||||
|
|
||||||
|
|
||||||
} // namespace lyx
|
} // namespace lyx
|
||||||
|
Loading…
Reference in New Issue
Block a user