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.
37 return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
40 QString toqstr(char_type ucs4)
42 union { char_type c; uint i; } u = { ucs4 };
43 return QString::fromUcs4(&u.i, 1);
46 docstring qstring_to_ucs4(QString const & qstr)
50 QVector<uint> const ucs4 = qstr.toUcs4();
51 return docstring((char_type const *)(ucs4.constData()), ucs4.size());
54 std::string fromqstr(QString const & str)
56 return str.isEmpty() ? std::string() : std::string(str.toUtf8());