2 * \file qstring_helper.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
10 * A collection of unicode conversion functions, using iconv.
15 #include "support/docstring.h"
22 QString toqstr(char const * str)
24 return QString::fromUtf8(str);
27 QString toqstr(std::string const & str)
29 return toqstr(str.c_str());
33 QString toqstr(docstring const & ucs4)
35 // If possible we let qt do the work, since this version does not
36 // need to be superfast.
39 return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
42 QString toqstr(char_type ucs4)
44 union { char_type c; uint i; } u = { ucs4 };
45 return QString::fromUcs4(&u.i, 1);
48 docstring qstring_to_ucs4(QString const & qstr)
52 QVector<uint> const ucs4 = qstr.toUcs4();
53 return docstring((char_type const *)(ucs4.constData()), ucs4.size());
56 std::string fromqstr(QString const & str)
58 return str.isEmpty() ? std::string() : std::string(str.toUtf8());