diff --git a/src/frontends/qt4/qt_helpers.C b/src/frontends/qt4/qt_helpers.C index 9c25e1ddda..56c20699b6 100644 --- a/src/frontends/qt4/qt_helpers.C +++ b/src/frontends/qt4/qt_helpers.C @@ -111,36 +111,12 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, } -QString const toqstr(char const * str) -{ - return QString::fromUtf8(str); -} - - -QString const toqstr(string const & str) -{ - return toqstr(str.c_str()); -} - - -void ucs4_to_qstring(char_type const * str, size_t ls, QString & s) -{ - s.reserve(ls); - s.clear(); - - for (size_t i = 0; i < ls; ++i) - s.append(ucs4_to_qchar(str[i])); -} - - void ucs4_to_qstring(lyx::docstring const & str, QString & s) { - size_t ls = str.size(); - s.reserve(ls); - s.clear(); - - for (size_t i = 0; i < ls; ++i) - s.append(ucs4_to_qchar(str[i])); + size_t const ls = str.size(); + s.resize(ls); + for (int i = ls; --i >= 0; ) + s[i] = ucs4_to_qchar(str[i]); } @@ -156,7 +132,6 @@ QString const toqstr(docstring const & ucs4) { QString s; ucs4_to_qstring(ucs4, s); - return s; } @@ -167,7 +142,6 @@ docstring const qstring_to_ucs4(QString const & qstr) docstring ucs4; for (int i = 0; i < ls; ++i) ucs4 += static_cast(qstr[i].unicode()); - return ucs4; } diff --git a/src/frontends/qt4/qt_helpers.h b/src/frontends/qt4/qt_helpers.h index fa96925da4..57c68f285a 100644 --- a/src/frontends/qt4/qt_helpers.h +++ b/src/frontends/qt4/qt_helpers.h @@ -16,13 +16,13 @@ #include "support/docstring.h" #include +#include #include #include class QComboBox; class QLineEdit; -class QString; class LengthCombo; @@ -45,12 +45,15 @@ void lengthToWidgets(QLineEdit * input, LengthCombo * combo, docstring const formatted(docstring const & text, int w = 80); /** - * toqstr - convert char * into unicode + * toqstr - convert char * into Qt's unicode (UTF16) * * Use this whenever there's a user-visible string that is encoded * for the locale (menus, dialogs etc.) */ -QString const toqstr(char const * str); +inline QString const toqstr(char const * str) +{ + return QString::fromUtf8(str); +} /** @@ -59,7 +62,10 @@ QString const toqstr(char const * str); * Use this whenever there's a user-visible string that is encoded * for the locale (menus, dialogs etc.) */ -QString const toqstr(std::string const & str); +inline QString const toqstr(std::string const & str) +{ + return toqstr(str.c_str()); +} /** @@ -67,18 +73,6 @@ QString const toqstr(std::string const & str); * * QString uses utf16 internally. */ -QString const toqstr(docstring const & ucs4); - -void ucs4_to_qstring(char_type const * str, size_t ls, QString & s); - -void ucs4_to_qstring(docstring const & str, QString & s); - -QString ucs4_to_qstring(docstring const & str); - -docstring const qstring_to_ucs4(QString const & qstr); - -void qstring_to_ucs4(QString const & qstr, std::vector & ucs4); - inline char_type const qchar_to_ucs4(QChar const & qchar) { return static_cast(qchar.unicode()); } @@ -87,6 +81,24 @@ inline QChar const ucs4_to_qchar(char_type const ucs4) { return QChar(static_cast(ucs4)); } +QString const toqstr(docstring const & ucs4); + +void ucs4_to_qstring(docstring const & str, QString & s); + +inline void ucs4_to_qstring(char_type const * str, size_t ls, QString & s) +{ + s.resize(ls); + for (int i = ls; --i >= 0; ) + s[i] = ucs4_to_qchar(str[i]); +} + + +QString ucs4_to_qstring(docstring const & str); + +docstring const qstring_to_ucs4(QString const & qstr); + +void qstring_to_ucs4(QString const & qstr, std::vector & ucs4); + /** * qt_ - i18nize string and convert to unicode *