mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-25 19:07:45 +00:00
Fixup 3dc54d4a
: fix string encoding issues with Qt4
The culprit here is the constructor QString(QByteArray const &): in Qt4, it would interpret the byte array as latin1, and in Qt5 as utf8. Therefore it is safer to use explicitly QString::fromUtf8 instead of this constructor. Several places where additionally simplified, in order to avoid some extra conversions.
This commit is contained in:
parent
3a7142d9bf
commit
938463b5d6
@ -43,7 +43,7 @@ namespace {
|
|||||||
QString const guiString(QString in)
|
QString const guiString(QString in)
|
||||||
{
|
{
|
||||||
// recode specially encoded chars in file names (URL encoding and underbar)
|
// recode specially encoded chars in file names (URL encoding and underbar)
|
||||||
return QString(QByteArray::fromPercentEncoding(in.toUtf8())).replace('_', ' ');
|
return QString::fromUtf8(QByteArray::fromPercentEncoding(in.toUtf8())).replace('_', ' ');
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace anon
|
} // namespace anon
|
||||||
|
@ -1872,11 +1872,9 @@ public:
|
|||||||
: tab_(tab)
|
: tab_(tab)
|
||||||
{
|
{
|
||||||
// Recode URL encoded chars via fromPercentEncoding()
|
// Recode URL encoded chars via fromPercentEncoding()
|
||||||
filename_ = (filename.extension() == "lyx") ?
|
string const fn = (filename.extension() == "lyx")
|
||||||
QString(QByteArray::fromPercentEncoding(
|
? filename.onlyFileNameWithoutExt() : filename.onlyFileName();
|
||||||
toqstr(filename.onlyFileNameWithoutExt()).toUtf8()))
|
filename_ = QString::fromUtf8(QByteArray::fromPercentEncoding(fn.c_str()));
|
||||||
: QString(QByteArray::fromPercentEncoding(
|
|
||||||
toqstr(filename.onlyFileName()).toUtf8()));
|
|
||||||
postfix_ = toqstr(filename.absoluteFilePath()).
|
postfix_ = toqstr(filename.absoluteFilePath()).
|
||||||
split("/", QString::SkipEmptyParts);
|
split("/", QString::SkipEmptyParts);
|
||||||
postfix_.pop_back();
|
postfix_.pop_back();
|
||||||
|
@ -1453,16 +1453,15 @@ std::string formatFPNumber(double x)
|
|||||||
|
|
||||||
docstring to_percent_encoding(docstring const & in, docstring const & ex)
|
docstring to_percent_encoding(docstring const & in, docstring const & ex)
|
||||||
{
|
{
|
||||||
QByteArray input = toqstr(in).toUtf8();
|
QByteArray input = to_utf8(in).c_str();
|
||||||
QByteArray excludes = toqstr(ex).toUtf8();
|
QByteArray excludes = to_utf8(ex).c_str();
|
||||||
return qstring_to_ucs4(QString(input.toPercentEncoding(excludes)));
|
return from_utf8(string(input.toPercentEncoding(excludes).data()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
string from_percent_encoding(string const & in)
|
string from_percent_encoding(string const & in)
|
||||||
{
|
{
|
||||||
QByteArray input = toqstr(in).toUtf8();
|
return QByteArray::fromPercentEncoding(in.c_str()).data();
|
||||||
return fromqstr(QString(QByteArray::fromPercentEncoding(input)));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user