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"
27 LyXErr & operator<<(LyXErr & err, QString const & str)
29 return err << fromqstr(str);
33 QString toqstr(char const * str)
35 return QString::fromUtf8(str);
38 QString toqstr(std::string const & str)
40 return toqstr(str.c_str());
44 QString toqstr(docstring const & ucs4)
46 // If possible we let qt do the work, since this version does not
47 // need to be superfast.
50 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
51 return QString::fromStdU32String(reinterpret_cast<std::u32string const &>(ucs4));
53 return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length());
57 QString toqstr(char_type ucs4)
59 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
60 return QString::fromStdU32String(std::u32string(1, ucs4));
62 union { char_type c; uint i; } u = { ucs4 };
63 return QString::fromUcs4(&u.i, 1);
67 docstring qstring_to_ucs4(QString const & qstr)
71 QVector<uint> const ucs4 = qstr.toUcs4();
72 return docstring((char_type const *)(ucs4.constData()), ucs4.size());
75 std::string fromqstr(QString const & str)
77 return str.isEmpty() ? std::string() : std::string(str.toUtf8());
80 QString charFilterRegExp(QString const & filter)
83 for (QChar const & c : filter) {
85 re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
87 re += QRegExp::escape(c);
92 QString charFilterRegExpC(QString const & filter)
95 for (QChar const & c : filter) {
97 re += "["+ QRegExp::escape(c) + QRegExp::escape(c.toUpper()) + "]";
99 re += QRegExp::escape(c);