diff options
Diffstat (limited to 'src/corelib/text/qlocale_unix.cpp')
-rw-r--r-- | src/corelib/text/qlocale_unix.cpp | 77 |
1 files changed, 23 insertions, 54 deletions
diff --git a/src/corelib/text/qlocale_unix.cpp b/src/corelib/text/qlocale_unix.cpp index 84afaa377c..a934f24c01 100644 --- a/src/corelib/text/qlocale_unix.cpp +++ b/src/corelib/text/qlocale_unix.cpp @@ -1,41 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2021 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** 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 Lesser General Public License Usage -** Alternatively, this file may be used under the terms of the GNU Lesser -** General Public License version 3 as published by the Free Software -** Foundation and appearing in the file LICENSE.LGPL3 included in the -** packaging of this file. Please review the following information to -** ensure the GNU Lesser General Public License version 3 requirements -** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 2.0 or (at your option) the GNU General -** Public license version 3 or any later version approved by the KDE Free -** Qt Foundation. The licenses are as published by the Free Software -** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 -** 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-2.0.html and -** https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ +// Copyright (C) 2022 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only #include "qlocale_p.h" @@ -47,6 +11,8 @@ QT_BEGIN_NAMESPACE +using namespace Qt::StringLiterals; + #ifndef QT_NO_SYSTEMLOCALE struct QSystemLocaleData { @@ -144,12 +110,12 @@ QLocale QSystemLocale::fallbackLocale() const if (lang.isEmpty()) lang = qEnvironmentVariable("LANG"); // if the locale is the "C" locale, then we can return the language we found here: - if (lang.isEmpty() || lang == QLatin1String("C") || lang == QLatin1String("POSIX")) + if (lang.isEmpty() || lang == "C"_L1 || lang == "POSIX"_L1) return QLocale(lang); // ... otherwise, if the first part of LANGUAGE says more than or // contradicts what we have, use that: - for (const auto &language : qEnvironmentVariable("LANGUAGE").tokenize(QLatin1Char(':'))) { + for (const auto &language : qEnvironmentVariable("LANGUAGE").tokenize(u':')) { if (contradicts(language, lang)) return QLocale(language); break; // We only look at the first entry. @@ -158,7 +124,7 @@ QLocale QSystemLocale::fallbackLocale() const return QLocale(lang); } -QVariant QSystemLocale::query(QueryType type, QVariant in) const +QVariant QSystemLocale::query(QueryType type, QVariant &&in) const { QSystemLocaleData *d = qSystemLocaleData(); @@ -260,9 +226,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const } case MeasurementSystem: { const QString meas_locale = QString::fromLatin1(d->lc_measurement_var); - if (meas_locale.compare(QLatin1String("Metric"), Qt::CaseInsensitive) == 0) + if (meas_locale.compare("Metric"_L1, Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; - if (meas_locale.compare(QLatin1String("Other"), Qt::CaseInsensitive) == 0) + if (meas_locale.compare("Other"_L1, Qt::CaseInsensitive) == 0) return QLocale::MetricSystem; return QVariant((int)QLocale(meas_locale).measurementSystem()); } @@ -276,28 +242,31 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const if (languages.isEmpty()) lst.append(QString::fromLatin1(d->lc_messages_var)); else - lst = languages.split(QLatin1Char(':')); + lst = languages.split(u':'); - // Inadequate for various cases of a language that's written in more - // than one script in the same country, e.g. Sindhi in India. - // However, can clients of the UILanguage query cope if we include script ? - for (int i = 0; i < lst.size(); ++i) { - QStringView lang, cntry; - if (qt_splitLocaleName(lst.at(i), &lang, nullptr, &cntry)) { - d->uiLanguages.append( - cntry.size() ? lang % QLatin1Char('-') % cntry : lang.toString()); + for (const QString &e : std::as_const(lst)) { + QStringView language, script, territory; + if (qt_splitLocaleName(e, &language, &script, &territory)) { + QString joined = language.isEmpty() ? u"und"_s : language.toString(); + if (!script.isEmpty()) + joined += u'-' + script; + if (!territory.isEmpty()) + joined += u'-' + territory; + d->uiLanguages.append(joined); } } return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages); } case StringToStandardQuotation: - return lc_messages.quoteString(qvariant_cast<QStringView>(in)); + return lc_messages.quoteString(qvariant_cast<QStringView>(std::move(in))); case StringToAlternateQuotation: - return lc_messages.quoteString(qvariant_cast<QStringView>(in), QLocale::AlternateQuotation); + return lc_messages.quoteString(qvariant_cast<QStringView>(std::move(in)), + QLocale::AlternateQuotation); case ListToSeparatedString: return lc_messages.createSeparatedList(in.toStringList()); case LocaleChanged: Q_ASSERT(false); + [[fallthrough]]; default: break; } |