summaryrefslogtreecommitdiffstats
path: root/src/linguist/shared/qm.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/shared/qm.cpp')
-rw-r--r--src/linguist/shared/qm.cpp69
1 files changed, 25 insertions, 44 deletions
diff --git a/src/linguist/shared/qm.cpp b/src/linguist/shared/qm.cpp
index 6eb9c874d..82605f492 100644
--- a/src/linguist/shared/qm.cpp
+++ b/src/linguist/shared/qm.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 The Qt Company Ltd.
-** Contact: https://www.qt.io/licensing/
-**
-** This file is part of the Qt Linguist of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:GPL-EXCEPT$
-** Commercial License Usage
-** Licensees holding valid commercial Qt licenses may use this file in
-** accordance with the commercial license agreement provided with the
-** Software or, alternatively, in accordance with the terms contained in
-** a written agreement between you and The Qt Company. For licensing terms
-** and conditions see https://www.qt.io/terms-conditions. For further
-** information use the contact form at https://www.qt.io/contact-us.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3 as published by the Free Software
-** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
-** included in the packaging of this file. Please review the following
-** information to ensure the GNU General Public License requirements will
-** be met: https://www.gnu.org/licenses/gpl-3.0.html.
-**
-** $QT_END_LICENSE$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "translator.h"
@@ -38,6 +13,7 @@
#include <QtCore/QFileInfo>
#include <QtCore/QMap>
#include <QtCore/QString>
+#include <QtCore/QStringDecoder>
QT_BEGIN_NAMESPACE
@@ -118,7 +94,7 @@ private:
QStringList m_translations;
};
-Q_DECLARE_TYPEINFO(ByteTranslatorMessage, Q_MOVABLE_TYPE);
+Q_DECLARE_TYPEINFO(ByteTranslatorMessage, Q_RELOCATABLE_TYPE);
bool ByteTranslatorMessage::operator<(const ByteTranslatorMessage& m) const
{
@@ -220,7 +196,7 @@ Prefix Releaser::commonPrefix(const ByteTranslatorMessage &m1, const ByteTransla
void Releaser::writeMessage(const ByteTranslatorMessage &msg, QDataStream &stream,
TranslatorSaveMode mode, Prefix prefix) const
{
- for (int i = 0; i < msg.translations().count(); ++i)
+ for (int i = 0; i < msg.translations().size(); ++i)
stream << quint8(Tag_Translation) << msg.translations().at(i);
if (mode == SaveEverything)
@@ -287,7 +263,7 @@ void Releaser::squeeze(TranslatorSaveMode mode)
{
m_dependencyArray.clear();
QDataStream depstream(&m_dependencyArray, QIODevice::WriteOnly);
- for (const QString &dep : qAsConst(m_dependencies))
+ for (const QString &dep : std::as_const(m_dependencies))
depstream << dep;
if (m_messages.isEmpty() && mode == SaveEverything)
@@ -381,7 +357,7 @@ void Releaser::squeeze(TranslatorSaveMode mode)
do {
const char *con = entry.value().constData();
- uint len = uint(entry.value().length());
+ uint len = uint(entry.value().size());
len = qMin(len, 255u);
t << quint8(len);
t.writeRawData(con, len);
@@ -452,7 +428,7 @@ static quint32 read32(const uchar *data)
static void fromBytes(const char *str, int len, QString *out, bool *utf8Fail)
{
QStringDecoder toUnicode(QStringDecoder::Utf8, QStringDecoder::Flag::Stateless);
- *out = toUnicode(str, len);
+ *out = toUnicode(QByteArrayView(str, len));
*utf8Fail = toUnicode.hasError();
}
@@ -469,8 +445,8 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
enum { Contexts = 0x2f, Hashes = 0x42, Messages = 0x69, NumerusRules = 0x88, Dependencies = 0x96, Language = 0xa7 };
// for squeezed but non-file data, this is what needs to be deleted
- const uchar *messageArray = 0;
- const uchar *offsetArray = 0;
+ const uchar *messageArray = nullptr;
+ const uchar *offsetArray = nullptr;
uint offsetLength = 0;
bool ok = true;
@@ -522,12 +498,12 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
QString strProN = QLatin1String("%n");
QLocale::Language l;
- QLocale::Country c;
- Translator::languageAndCountry(translator.languageCode(), &l, &c);
+ QLocale::Territory c;
+ Translator::languageAndTerritory(translator.languageCode(), &l, &c);
QStringList numerusForms;
bool guessPlurals = true;
if (getNumerusInfo(l, c, 0, &numerusForms, 0))
- guessPlurals = (numerusForms.count() == 1);
+ guessPlurals = (numerusForms.size() == 1);
QString context, sourcetext, comment;
QStringList translations;
@@ -546,14 +522,19 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
goto end;
case Tag_Translation: {
int len = read32(m);
- if (len % 1) {
+ m += 4;
+
+ // -1 indicates an empty string
+ // Otherwise streaming format is UTF-16 -> 2 bytes per character
+ if ((len != -1) && (len & 1)) {
cd.appendError(QLatin1String("QM-Format error"));
return false;
}
- m += 4;
- QString str = QString((const QChar *)m, len/2);
+ QString str;
+ if (len != -1)
+ str = QString((const QChar *)m, len / 2);
if (QSysInfo::ByteOrder == QSysInfo::LittleEndian) {
- for (int i = 0; i < str.length(); ++i)
+ for (int i = 0; i < str.size(); ++i)
str[i] = QChar((str.at(i).unicode() >> 8) +
((str.at(i).unicode() << 8) & 0xff00));
}
@@ -600,7 +581,7 @@ bool loadQM(Translator &translator, QIODevice &dev, ConversionData &cd)
end:;
TranslatorMessage msg;
msg.setType(TranslatorMessage::Finished);
- if (translations.count() > 1) {
+ if (translations.size() > 1) {
// If guessPlurals is not false here, plural form discard messages
// will be spewn out later.
msg.setPlural(true);
@@ -639,8 +620,8 @@ bool saveQM(const Translator &translator, QIODevice &dev, ConversionData &cd)
{
Releaser releaser(translator.languageCode());
QLocale::Language l;
- QLocale::Country c;
- Translator::languageAndCountry(translator.languageCode(), &l, &c);
+ QLocale::Territory c;
+ Translator::languageAndTerritory(translator.languageCode(), &l, &c);
QByteArray rules;
if (getNumerusInfo(l, c, &rules, 0, 0))
releaser.setNumerusRules(rules);