]> git.lyx.org Git - lyx.git/blob - src/support/qstring_helpers.cpp
Fix text direction issue for InsetInfo in RTL context
[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/qstring_helpers.h"
16
17 #include "support/debug.h"
18 #include "support/docstring.h"
19
20 #include <QString>
21 #include <QVector>
22
23 namespace lyx {
24
25 LyXErr & operator<<(LyXErr & err, QString const & str)
26 {
27         return err << fromqstr(str);
28 }
29
30
31 QString toqstr(char const * str)
32 {
33         return QString::fromUtf8(str);
34 }
35
36 QString toqstr(std::string const & str)
37 {
38         return toqstr(str.c_str());
39 }
40
41
42 QString toqstr(docstring const & ucs4)
43 {
44         // If possible we let qt do the work, since this version does not
45         // need to be superfast.
46         if (ucs4.empty())
47                 return QString();
48         return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
49 }
50
51 QString toqstr(char_type ucs4)
52 {
53         union { char_type c; uint i; } u = { ucs4 };
54         return QString::fromUcs4(&u.i, 1);
55 }
56
57 docstring qstring_to_ucs4(QString const & qstr)
58 {
59         if (qstr.isEmpty())
60                 return docstring();
61         QVector<uint> const ucs4 = qstr.toUcs4();
62         return docstring((char_type const *)(ucs4.constData()), ucs4.size());
63 }
64
65 std::string fromqstr(QString const & str)
66 {
67         return str.isEmpty() ? std::string() : std::string(str.toUtf8());
68 }
69
70 } // namespace lyx