microoptimization

git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@15493 a592a061-630c-0410-9148-cb99ea01b6c8
This commit is contained in:
André Pönitz 2006-10-22 19:33:37 +00:00
parent 7c595cb763
commit 8a1e6d6759
2 changed files with 32 additions and 46 deletions

View File

@ -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<char_type>(qstr[i].unicode());
return ucs4;
}

View File

@ -16,13 +16,13 @@
#include "support/docstring.h"
#include <QChar>
#include <QString>
#include <vector>
#include <utility>
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<char_type> & ucs4);
inline char_type const qchar_to_ucs4(QChar const & qchar) {
return static_cast<char_type>(qchar.unicode());
}
@ -87,6 +81,24 @@ inline QChar const ucs4_to_qchar(char_type const ucs4) {
return QChar(static_cast<unsigned short>(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<char_type> & ucs4);
/**
* qt_ - i18nize string and convert to unicode
*