X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fsupport%2Fqstring_helpers.cpp;h=4f63167b4305f665e9cb04403b346a94054a73ee;hb=8d640dc77608bedddb5b00982c23665584f52d21;hp=27b740e6cac354a2e1261dfcdc666b158880b17d;hpb=55217e352c5dd1e2f912ed0b6e565002b16cfcc1;p=lyx.git diff --git a/src/support/qstring_helpers.cpp b/src/support/qstring_helpers.cpp index 27b740e6ca..4f63167b43 100644 --- a/src/support/qstring_helpers.cpp +++ b/src/support/qstring_helpers.cpp @@ -1,36 +1,70 @@ /** - * \file qstring_helpers.cpp + * \file qstring_helper.cpp * This file is part of LyX, the document processor. * Licence details can be found in the file COPYING. * * \author Dekel Tsur - * \author Jürgen Spitzmüller * * Full author contact details are available in file CREDITS. + * + * A collection of unicode conversion functions, using iconv. */ #include -#include "qstring_helpers.h" -#include "unicode.h" +#include "support/qstring_helpers.h" -#include +#include "support/debug.h" +#include "support/docstring.h" +#include +#include namespace lyx { -using std::string; +LyXErr & operator<<(LyXErr & err, QString const & str) +{ + return err << fromqstr(str); +} + -docstring const qstring_to_ucs4(QString const & qstr) +QString toqstr(char const * str) { - QVector const ucs4 = qstr.toUcs4(); - return docstring(ucs4.begin(), ucs4.end()); + return QString::fromUtf8(str); +} + +QString toqstr(std::string const & str) +{ + return toqstr(str.c_str()); } -string const fromqstr(QString const & str) +QString toqstr(docstring const & ucs4) +{ + // If possible we let qt do the work, since this version does not + // need to be superfast. + if (ucs4.empty()) + return QString(); + return QString::fromUcs4((uint const *)ucs4.data(), ucs4.length()); +} + +QString toqstr(char_type ucs4) +{ + union { char_type c; uint i; } u = { ucs4 }; + return QString::fromUcs4(&u.i, 1); +} + +docstring qstring_to_ucs4(QString const & qstr) +{ + if (qstr.isEmpty()) + return docstring(); + QVector const ucs4 = qstr.toUcs4(); + return docstring((char_type const *)(ucs4.constData()), ucs4.size()); +} + +std::string fromqstr(QString const & str) { - return str.isEmpty() ? string() : string(str.toUtf8()); + return str.isEmpty() ? std::string() : std::string(str.toUtf8()); } } // namespace lyx