]> git.lyx.org Git - lyx.git/blob - src/support/qstring_helpers.C
fix compiler warnings about unused parameter
[lyx.git] / src / support / qstring_helpers.C
1 /**
2  * \file qstring_helpers.C
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  * \author Jürgen Spitzmüller
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "qstring_helpers.h"
15
16 #include <QVector>
17
18
19 namespace lyx {
20
21 using std::string;
22
23 #if QT_VERSION < 0x040200
24 // We use QString::fromUcs4 in Qt 4.2 and higher
25 QString const toqstr(docstring const & str)
26 {
27         QString s;
28         int i = static_cast<int>(str.size()); 
29         s.resize(i);
30         for (; --i >= 0;)
31                 s[i] = ucs4_to_qchar(str[i]);
32         return s;
33 }
34 #endif
35
36
37 docstring const qstring_to_ucs4(QString const & qstr)
38 {
39 #if QT_VERSION >= 0x040200
40         QVector<uint> const ucs4 = qstr.toUcs4();
41         return docstring(ucs4.begin(), ucs4.end());
42 #else
43         // This does not properly convert surrogate pairs
44         int const ls = qstr.size();
45         docstring ucs4;
46         for (int i = 0; i < ls; ++i)
47                 ucs4 += static_cast<char_type>(qstr[i].unicode());
48         return ucs4;
49 #endif
50 }
51
52
53 string const fromqstr(QString const & str)
54 {
55         return str.isEmpty() ? string() : string(str.toUtf8());
56 }
57
58 } // namespace lyx