summaryrefslogtreecommitdiffstats
path: root/src/linguist/shared/po.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/linguist/shared/po.cpp')
-rw-r--r--src/linguist/shared/po.cpp77
1 files changed, 26 insertions, 51 deletions
diff --git a/src/linguist/shared/po.cpp b/src/linguist/shared/po.cpp
index d9aa24bbd..1da8b95d2 100644
--- a/src/linguist/shared/po.cpp
+++ b/src/linguist/shared/po.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"
@@ -52,7 +27,7 @@ static QString poEscapedString(const QString &prefix, const QString &keyword,
QStringList lines;
int off = 0;
QString res;
- while (off < ba.length()) {
+ while (off < ba.size()) {
ushort c = ba[off++].unicode();
switch (c) {
case '\n':
@@ -88,7 +63,7 @@ static QString poEscapedString(const QString &prefix, const QString &keyword,
if (c < 32) {
res += QLatin1String("\\x");
res += QString::number(c, 16);
- if (off < ba.length() && isxdigit(ba[off].unicode()))
+ if (off < ba.size() && isxdigit(ba[off].unicode()))
res += QLatin1String("\"\"");
} else {
res += QChar(c);
@@ -100,15 +75,15 @@ static QString poEscapedString(const QString &prefix, const QString &keyword,
lines.append(res);
if (!lines.isEmpty()) {
if (!noWrap) {
- if (lines.count() != 1 ||
- lines.first().length() > MAX_LEN - keyword.length() - prefix.length() - 3)
+ if (lines.size() != 1 ||
+ lines.first().size() > MAX_LEN - keyword.size() - prefix.size() - 3)
{
const QStringList olines = lines;
lines = QStringList(QString());
- const int maxlen = MAX_LEN - prefix.length() - 2;
+ const int maxlen = MAX_LEN - prefix.size() - 2;
for (const QString &line : olines) {
int off = 0;
- while (off + maxlen < line.length()) {
+ while (off + maxlen < line.size()) {
int idx = line.lastIndexOf(QLatin1Char(' '), off + maxlen - 1) + 1;
if (idx == off) {
#ifdef HARD_WRAP_LONG_WORDS
@@ -126,7 +101,7 @@ static QString poEscapedString(const QString &prefix, const QString &keyword,
lines.append(line.mid(off));
}
}
- } else if (lines.count() > 1) {
+ } else if (lines.size() > 1) {
lines.prepend(QString());
}
}
@@ -158,10 +133,10 @@ static QString poEscapedLines(const QString &prefix, bool addSpace, const QStrin
static QString poWrappedEscapedLines(const QString &prefix, bool addSpace, const QString &line)
{
- const int maxlen = MAX_LEN - prefix.length() - addSpace;
+ const int maxlen = MAX_LEN - prefix.size() - addSpace;
QStringList lines;
int off = 0;
- while (off + maxlen < line.length()) {
+ while (off + maxlen < line.size()) {
int idx = line.lastIndexOf(QLatin1Char(' '), off + maxlen - 1);
if (idx < off) {
#if 0 //def HARD_WRAP_LONG_WORDS
@@ -227,11 +202,11 @@ static QByteArray slurpEscapedString(const QList<QByteArray> &lines, int &l,
break;
offset++;
forever {
- if (offset == line.length())
+ if (offset == line.size())
goto premature_eol;
uchar c = line[offset++];
if (c == '"') {
- if (offset == line.length())
+ if (offset == line.size())
break;
while (isspace(line[offset]))
offset++;
@@ -244,7 +219,7 @@ static QByteArray slurpEscapedString(const QList<QByteArray> &lines, int &l,
continue;
}
if (c == '\\') {
- if (offset == line.length())
+ if (offset == line.size())
goto premature_eol;
c = line[offset++];
switch (c) {
@@ -285,14 +260,14 @@ static QByteArray slurpEscapedString(const QList<QByteArray> &lines, int &l,
case '7':
stoff = offset - 1;
while ((c = line[offset]) >= '0' && c <= '7')
- if (++offset == line.length())
+ if (++offset == line.size())
goto premature_eol;
msg += line.mid(stoff, offset - stoff).toUInt(0, 8);
break;
case 'x':
stoff = offset;
while (isxdigit(line[offset]))
- if (++offset == line.length())
+ if (++offset == line.size())
goto premature_eol;
msg += line.mid(stoff, offset - stoff).toUInt(0, 16);
break;
@@ -435,7 +410,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
bool isObsolete = line.startsWith("#~ msgstr");
const QByteArray prefix = isObsolete ? "#~ " : "";
while (true) {
- int idx = line.indexOf(' ', prefix.length());
+ int idx = line.indexOf(' ', prefix.size());
QByteArray str = slurpEscapedString(lines, l, idx, prefix, cd);
item.msgStr.append(str);
if (l + 1 >= lines.size() || !isTranslationLine(lines.at(l + 1)))
@@ -476,7 +451,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
.arg(QString::fromLatin1(hdrValue)));
error = true;
// This will avoid a flood of conversion errors.
- toUnicode = QStringConverter::Latin1;
+ toUnicode = QStringDecoder(QStringConverter::Latin1);
} else {
QByteArray cod = hdrValue.mid(20);
auto enc = QStringConverter::encodingForName(cod);
@@ -485,9 +460,9 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
.arg(QString::fromLatin1(cod)));
error = true;
// This will avoid a flood of conversion errors.
- toUnicode = QStringConverter::Latin1;
+ toUnicode = QStringDecoder(QStringConverter::Latin1);
} else {
- toUnicode = *enc;
+ toUnicode = QStringDecoder(*enc);
}
}
} else if (hdrName == "Content-Transfer-Encoding") {
@@ -516,7 +491,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
"Plural-Forms", "X-Language", "X-Source-Language", "X-Qt-Contexts"
};
uint cdh = 0;
- for (int cho = 0; cho < hdrOrder.length(); cho++) {
+ for (int cho = 0; cho < hdrOrder.size(); cho++) {
for (;; cdh++) {
if (cdh == sizeof(dfltHdrs)/sizeof(dfltHdrs[0])) {
extras[QLatin1String("po-headers")] =
@@ -573,7 +548,7 @@ bool loadPO(Translator &translator, QIODevice &dev, ConversionData &cd)
msg.setTranslatorComment(toUnicode(item.translatorComments));
msg.setPlural(item.isPlural || item.msgStr.size() > 1);
QStringList translations;
- for (const QByteArray &bstr : qAsConst(item.msgStr)) {
+ for (const QByteArray &bstr : std::as_const(item.msgStr)) {
QString str = toUnicode(bstr);
str.replace(QChar(Translator::TextVariantSeparator),
QChar(Translator::BinaryVariantSeparator));
@@ -754,8 +729,8 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &)
addPoHeader(headers, hdrOrder, "Content-Transfer-Encoding", QLatin1String("8bit"));
if (!translator.languageCode().isEmpty()) {
QLocale::Language l;
- QLocale::Country c;
- Translator::languageAndCountry(translator.languageCode(), &l, &c);
+ QLocale::Territory c;
+ Translator::languageAndTerritory(translator.languageCode(), &l, &c);
const char *gettextRules;
if (getNumerusInfo(l, c, 0, 0, &gettextRules))
addPoHeader(headers, hdrOrder, "Plural-Forms", QLatin1String(gettextRules));
@@ -766,7 +741,7 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &)
if (qtContexts)
addPoHeader(headers, hdrOrder, "X-Qt-Contexts", QLatin1String("true"));
QString hdrStr;
- for (const QString &hdr : qAsConst(hdrOrder)) {
+ for (const QString &hdr : std::as_const(hdrOrder)) {
hdrStr += hdr;
hdrStr += QLatin1String(": ");
hdrStr += headers.value(makePoHeader(hdr));
@@ -820,7 +795,7 @@ bool savePO(const Translator &translator, QIODevice &dev, ConversionData &)
// This is fuzzy logic, as we don't know whether the string is
// actually used with QString::arg().
for (int off = 0; (off = source.indexOf(QLatin1Char('%'), off)) >= 0; ) {
- if (++off >= source.length())
+ if (++off >= source.size())
break;
if (source.at(off) == QLatin1Char('n') || source.at(off).isDigit()) {
flags.append(QLatin1String("qt-format"));