Add a QLocale(QStringView) constructor

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 <marten.nordheim@qt.io>
bb10
Edward Welbourne 2021-08-31 17:53:15 +02:00
parent dc65267ad8
commit 6da648ad83
3 changed files with 23 additions and 11 deletions

View File

@ -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<QLocalePrivate>, 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()

View File

@ -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);

View File

@ -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