]> git.lyx.org Git - lyx.git/blob - src/support/qstring_helpers.cpp
1e421ca132552e08e624e8abfb22e27d336d85aa
[lyx.git] / src / support / qstring_helpers.cpp
1 /**
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.
5  *
6  * \author Dekel Tsur
7  *
8  * Full author contact details are available in file CREDITS.
9  *
10  * A collection of unicode conversion functions, using iconv.
11  */
12
13 #include <config.h>
14
15 #include "support/docstring.h"
16 #include "support/docstring.h"
17
18 #include <QString>
19 #include <QVector>
20
21 namespace lyx {
22
23 QString toqstr(char const * str)
24 {
25         return QString::fromUtf8(str);
26 }
27
28 QString toqstr(std::string const & str)
29 {
30         return toqstr(str.c_str());
31 }
32
33
34 QString toqstr(docstring const & ucs4)
35 {
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());
39 }
40
41 QString toqstr(char_type ucs4)
42 {
43         union { char_type c; uint i; } u = { ucs4 };
44         return QString::fromUcs4(&u.i, 1);
45 }
46
47 docstring qstring_to_ucs4(QString const & qstr)
48 {
49         if (qstr.isEmpty())
50                 return docstring();
51         QVector<uint> const ucs4 = qstr.toUcs4();
52         return docstring((char_type const *)(ucs4.constData()), ucs4.size());
53 }
54
55 std::string fromqstr(QString const & str)
56 {
57         return str.isEmpty() ? std::string() : std::string(str.toUtf8());
58 }
59
60 } // namespace lyx