2 * \file qstring_helpers.C
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)
28 int i = static_cast<int>(str.size());
31 s[i] = ucs4_to_qchar(str[i]);
37 docstring const qstring_to_ucs4(QString const & qstr)
39 #if QT_VERSION >= 0x040200
40 QVector<uint> const ucs4 = qstr.toUcs4();
41 return docstring(ucs4.begin(), ucs4.end());
43 // This does not properly convert surrogate pairs
44 int const ls = qstr.size();
46 for (int i = 0; i < ls; ++i)
47 ucs4 += static_cast<char_type>(qstr[i].unicode());
53 string const fromqstr(QString const & str)
55 return str.isEmpty() ? string() : string(str.toUtf8());