Port QLocale::quoteString from QStringRef to QStringView

Task-number: QTBUG-84319
Change-Id: I29726ebfda7a5f51a0a6ee29e905b0b904256c8d
Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Lars Knoll 2020-05-22 14:49:30 +02:00
parent ce8c33e710
commit ecacb3c62f
7 changed files with 16 additions and 18 deletions

View File

@ -1124,22 +1124,20 @@ QLocale::NumberOptions QLocale::numberOptions() const
} }
/*! /*!
\fn QString QLocale::quoteString(const QString &str, QuotationStyle style) const
\since 4.8 \since 4.8
Returns \a str quoted according to the current locale using the given Returns \a str quoted according to the current locale using the given
quotation \a style. quotation \a style.
*/ */
QString QLocale::quoteString(const QString &str, QuotationStyle style) const
{
return quoteString(QStringRef(&str), style);
}
/*! /*!
\since 4.8 \since 6.0
\overload \overload
*/ */
QString QLocale::quoteString(const QStringRef &str, QuotationStyle style) const QString QLocale::quoteString(QStringView str, QuotationStyle style) const
{ {
#ifndef QT_NO_SYSTEMLOCALE #ifndef QT_NO_SYSTEMLOCALE
if (d->m_data == systemData()) { if (d->m_data == systemData()) {

View File

@ -1120,8 +1120,9 @@ public:
NumberOptions numberOptions() const; NumberOptions numberOptions() const;
enum QuotationStyle { StandardQuotation, AlternateQuotation }; enum QuotationStyle { StandardQuotation, AlternateQuotation };
QString quoteString(const QString &str, QuotationStyle style = StandardQuotation) const; QString quoteString(const QString &str, QuotationStyle style = StandardQuotation) const
QString quoteString(const QStringRef &str, QuotationStyle style = StandardQuotation) const; { return quoteString(QStringView(str), style); }
QString quoteString(QStringView str, QuotationStyle style = StandardQuotation) const;
QString createSeparatedList(const QStringList &strl) const; QString createSeparatedList(const QStringList &strl) const;

View File

@ -380,7 +380,7 @@ static QString macFormatCurrency(const QSystemLocale::CurrencyToStringArgument &
return QString::fromCFString(result); return QString::fromCFString(result);
} }
static QVariant macQuoteString(QSystemLocale::QueryType type, const QStringRef &str) static QVariant macQuoteString(QSystemLocale::QueryType type, QStringView str)
{ {
QString begin, end; QString begin, end;
QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent(); QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent();
@ -494,7 +494,7 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
} }
case StringToStandardQuotation: case StringToStandardQuotation:
case StringToAlternateQuotation: case StringToAlternateQuotation:
return macQuoteString(type, in.value<QStringRef>()); return macQuoteString(type, in.value<QStringView>());
default: default:
break; break;
} }

View File

@ -116,8 +116,8 @@ public:
CurrencyToString, // QString in: qlonglong, qulonglong or double CurrencyToString, // QString in: qlonglong, qulonglong or double
Collation, // QString Collation, // QString
UILanguages, // QStringList UILanguages, // QStringList
StringToStandardQuotation, // QString in: QStringRef to quote StringToStandardQuotation, // QString in: QStringView to quote
StringToAlternateQuotation, // QString in: QStringRef to quote StringToAlternateQuotation, // QString in: QStringView to quote
ScriptId, // uint ScriptId, // uint
ListToSeparatedString, // QString ListToSeparatedString, // QString
LocaleChanged, // system locale changed LocaleChanged, // system locale changed
@ -515,7 +515,7 @@ Q_STATIC_ASSERT(!ascii_isspace(uchar('\377')));
QT_END_NAMESPACE QT_END_NAMESPACE
Q_DECLARE_METATYPE(QStringRef) Q_DECLARE_METATYPE(QStringView)
Q_DECLARE_METATYPE(QList<Qt::DayOfWeek>) Q_DECLARE_METATYPE(QList<Qt::DayOfWeek>)
#ifndef QT_NO_SYSTEMLOCALE #ifndef QT_NO_SYSTEMLOCALE
Q_DECLARE_METATYPE(QSystemLocale::CurrencyToStringArgument) Q_DECLARE_METATYPE(QSystemLocale::CurrencyToStringArgument)

View File

@ -283,9 +283,9 @@ QVariant QSystemLocale::query(QueryType type, QVariant in) const
return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages); return d->uiLanguages.isEmpty() ? QVariant() : QVariant(d->uiLanguages);
} }
case StringToStandardQuotation: case StringToStandardQuotation:
return lc_messages.quoteString(qvariant_cast<QStringRef>(in)); return lc_messages.quoteString(qvariant_cast<QStringView>(in));
case StringToAlternateQuotation: case StringToAlternateQuotation:
return lc_messages.quoteString(qvariant_cast<QStringRef>(in), QLocale::AlternateQuotation); return lc_messages.quoteString(qvariant_cast<QStringView>(in), QLocale::AlternateQuotation);
case ListToSeparatedString: case ListToSeparatedString:
return lc_messages.createSeparatedList(in.toStringList()); return lc_messages.createSeparatedList(in.toStringList());
case LocaleChanged: case LocaleChanged:

View File

@ -156,9 +156,9 @@ QVariant QAndroidSystemLocale::query(QueryType type, QVariant in) const
return QString(); return QString();
} }
case StringToStandardQuotation: case StringToStandardQuotation:
return m_locale.quoteString(in.value<QStringRef>()); return m_locale.quoteString(in.value<QStringView>());
case StringToAlternateQuotation: case StringToAlternateQuotation:
return m_locale.quoteString(in.value<QStringRef>(), QLocale::AlternateQuotation); return m_locale.quoteString(in.value<QStringView>(), QLocale::AlternateQuotation);
case ListToSeparatedString: case ListToSeparatedString:
return m_locale.createSeparatedList(in.value<QStringList>()); return m_locale.createSeparatedList(in.value<QStringList>());
case LocaleChanged: case LocaleChanged:

View File

@ -58,7 +58,6 @@
#endif #endif
Q_DECLARE_METATYPE(QLocale::FormatType) Q_DECLARE_METATYPE(QLocale::FormatType)
Q_DECLARE_METATYPE(QStringView)
class tst_QLocale : public QObject class tst_QLocale : public QObject
{ {