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"
16 #include "support/docstring.h"
23 QString toqstr(char const * str)
25 return QString::fromUtf8(str);
28 QString toqstr(std::string const & str)
30 return toqstr(str.c_str());
34 QString toqstr(docstring const & ucs4)
36 // If possible we let qt do the work, since this version does not
37 // need to be superfast.
38 return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
41 QString toqstr(char_type ucs4)
43 union { char_type c; uint i; } u = { ucs4 };
44 return QString::fromUcs4(&u.i, 1);
47 docstring qstring_to_ucs4(QString const & qstr)
51 QVector<uint> const ucs4 = qstr.toUcs4();
52 return docstring((char_type const *)(ucs4.constData()), ucs4.size());
55 std::string fromqstr(QString const & str)
57 return str.isEmpty() ? std::string() : std::string(str.toUtf8());