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/qstring_helpers.h"
17 #include "support/debug.h"
18 #include "support/docstring.h"
19 #include "support/qstring_helpers.h"
26 LyXErr & operator<<(LyXErr & err, QString const & str)
28 return err << fromqstr(str);
32 QString toqstr(char const * str)
34 return QString::fromUtf8(str);
37 QString toqstr(std::string const & str)
39 return toqstr(str.c_str());
43 QString toqstr(docstring const & ucs4)
45 // If possible we let qt do the work, since this version does not
46 // need to be superfast.
49 return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
52 QString toqstr(char_type ucs4)
54 union { char_type c; uint i; } u = { ucs4 };
55 return QString::fromUcs4(&u.i, 1);
58 docstring qstring_to_ucs4(QString const & qstr)
62 QVector<uint> const ucs4 = qstr.toUcs4();
63 return docstring((char_type const *)(ucs4.constData()), ucs4.size());
66 std::string fromqstr(QString const & str)
68 return str.isEmpty() ? std::string() : std::string(str.toUtf8());
71 QString charFilterRegExp(QString const & filter)
74 for (int i = 0; i < filter.length(); ++i) {
77 re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
79 re += QRegExp::escape(c);
84 QString charFilterRegExpC(QString const & filter)
87 for (int i = 0; i < filter.length(); ++i) {
90 re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
92 re += QRegExp::escape(c);