From 6da648ad836c6d2247ab37f440c0a4368cebc778 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Tue, 31 Aug 2021 17:53:15 +0200 Subject: Add a QLocale(QStringView) constructor MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Only a few more internals just needed to change to take QStringView, to connect up the constructor with internals already long since converted. [ChangeLog][QtCore][QLocale] Added QLocale(QStringView) constructor. Change-Id: Iec31391e6168f333b4b6fc633c3d7d01872f83b3 Reviewed-by: MÃ¥rten Nordheim --- src/corelib/text/qlocale.cpp | 27 ++++++++++++++++++--------- src/corelib/text/qlocale.h | 5 ++++- src/corelib/text/qlocale_p.h | 2 +- 3 files changed, 23 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/corelib/text/qlocale.cpp b/src/corelib/text/qlocale.cpp index bc32dfeaaa..145a2439e5 100644 --- a/src/corelib/text/qlocale.cpp +++ b/src/corelib/text/qlocale.cpp @@ -550,7 +550,7 @@ bool qt_splitLocaleName(QStringView name, QStringView *lang, QStringView *script return state != LangState; } -QLocaleId QLocaleId::fromName(const QString &name) +QLocaleId QLocaleId::fromName(QStringView name) { QStringView lang; QStringView script; @@ -786,9 +786,9 @@ QBasicAtomicInt QLocalePrivate::s_generation = Q_BASIC_ATOMIC_INITIALIZER(0); Q_GLOBAL_STATIC_WITH_ARGS(QSharedDataPointer, defaultLocalePrivate, (new QLocalePrivate(defaultData(), defaultIndex()))) -static QLocalePrivate *localePrivateByName(const QString &name) +static QLocalePrivate *localePrivateByName(QStringView name) { - if (name == QLatin1String("C")) + if (name == u"C") return c_private(); const int index = QLocaleData::findLocaleIndex(QLocaleId::fromName(name)); Q_ASSERT(index >= 0 && size_t(index) < std::size(locale_data) - 1); @@ -920,9 +920,12 @@ QLocale::QLocale(QLocalePrivate &dd) /*! - Constructs a QLocale object with the specified \a name, - which has the format - "language[_script][_territory][.codeset][@modifier]" or "C", where: + \since 6.3 + + Constructs a QLocale object with the specified \a name. + + The name has the format "language[_script][_territory][.codeset][@modifier]" + or "C", where: \list \li language is a lowercase, two-letter, ISO 639 language code (some @@ -945,19 +948,25 @@ QLocale::QLocale(QLocalePrivate &dd) \sa bcp47Name(), {Matching combinations of language, script and territory} */ - -QLocale::QLocale(const QString &name) +QLocale::QLocale(QStringView name) : d(localePrivateByName(name)) { } +#if QT_STRINGVIEW_LEVEL < 2 +/*! + \fn QLocale::QLocale(const QString &name) + \overload +*/ +#endif + /*! Constructs a QLocale object initialized with the default locale. If no default locale was set using setDefault(), this locale will be the same as the one returned by system(). - \sa setDefault() + \sa setDefault(), system() */ QLocale::QLocale() diff --git a/src/corelib/text/qlocale.h b/src/corelib/text/qlocale.h index 7611fc6efa..de72e2024f 100644 --- a/src/corelib/text/qlocale.h +++ b/src/corelib/text/qlocale.h @@ -925,7 +925,10 @@ public: Q_FLAG(DataSizeFormats) QLocale(); - explicit QLocale(const QString &name); +#if QT_STRINGVIEW_LEVEL < 2 + explicit QLocale(const QString &name) : QLocale(qToStringViewIgnoringNull(name)) {} +#endif + explicit QLocale(QStringView name); QLocale(Language language, Territory territory); QLocale(Language language, Script script = AnyScript, Territory territory = AnyTerritory); QLocale(const QLocale &other); diff --git a/src/corelib/text/qlocale_p.h b/src/corelib/text/qlocale_p.h index 3c0e8f65b9..449ffc4d9c 100644 --- a/src/corelib/text/qlocale_p.h +++ b/src/corelib/text/qlocale_p.h @@ -148,7 +148,7 @@ namespace QIcu { struct QLocaleId { - [[nodiscard]] Q_CORE_EXPORT static QLocaleId fromName(const QString &name); + [[nodiscard]] Q_CORE_EXPORT static QLocaleId fromName(QStringView name); [[nodiscard]] inline bool operator==(QLocaleId other) const { return language_id == other.language_id && script_id == other.script_id && territory_id == other.territory_id; } [[nodiscard]] inline bool operator!=(QLocaleId other) const -- cgit v1.2.3