2 * \file qstring_helpers.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
7 * \author Jürgen Spitzmüller
9 * Full author contact details are available in file CREDITS.
14 #include "qstring_helpers.h"
23 #if QT_VERSION < 0x040200
24 // We use QString::fromUcs4 in Qt 4.2 and higher
25 QString const toqstr(docstring const & str)
27 // This does not properly convert surrogate pairs
29 int i = static_cast<int>(str.size());
32 s[i] = ucs4_to_qchar(str[i]);
38 docstring const qstring_to_ucs4(QString const & qstr)
40 #if QT_VERSION >= 0x040200
41 QVector<uint> const ucs4 = qstr.toUcs4();
42 return docstring(ucs4.begin(), ucs4.end());
44 // This does not properly convert surrogate pairs
45 int const ls = qstr.size();
47 for (int i = 0; i < ls; ++i)
48 ucs4 += qchar_to_ucs4(qstr[i].unicode());
54 string const fromqstr(QString const & str)
56 return str.isEmpty() ? string() : string(str.toUtf8());