diff options
Diffstat (limited to 'src/corelib/tools')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 86 | ||||
-rw-r--r-- | src/corelib/tools/qlocale.h | 8 | ||||
-rw-r--r-- | src/corelib/tools/qlocale_p.h | 2 |
3 files changed, 95 insertions, 1 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index 985889c401..10ad0cc54d 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -59,6 +59,7 @@ QT_END_NAMESPACE #include "qdatetime.h" #include "qstringlist.h" #include "qvariant.h" +#include "qstringbuilder.h" #if defined(Q_WS_WIN) # include "qt_windows.h" # include <time.h> @@ -1313,6 +1314,33 @@ static QString macFormatCurrency(const QVariant &in) return QCFString::toQString(result); } +static QVariant macQuotationSymbol(QSystemLocale::QueryType type, const QVariant &in) +{ +#if MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_6 + if (QSysInfo::MacintoshVersion < QSysInfo::MV_10_6) + return QVariant(); + + QCFType<CFLocaleRef> locale = CFLocaleCopyCurrent(); + switch (type) { + case QSystemLocale::QuotationBegin: + if (in.toInt() == QLocale::StandardQuotation) + return QCFString::toQString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationBeginDelimiterKey))); + else + return QCFString::toQString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationBeginDelimiterKey))); + break; + case QSystemLocale::QuotationEnd: + if (in.toInt() == QLocale::StandardQuotation) + return QCFString::toQString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleQuotationEndDelimiterKey))); + else + return QCFString::toQString(static_cast<CFStringRef>(CFLocaleGetValue(locale, kCFLocaleAlternateQuotationEndDelimiterKey))); + break; + default: + break; + } +#endif + return QVariant(); +} + static void getMacPreferredLanguageAndCountry(QString *language, QString *country) { QCFType<CFArrayRef> languages = (CFArrayRef)CFPreferencesCopyValue( @@ -1400,6 +1428,10 @@ QVariant QSystemLocale::query(QueryType type, QVariant in = QVariant()) const return QVariant(macCurrencySymbol(QLocale::CurrencySymbolFormat(in.toUInt()))); case FormatCurrency: return macFormatCurrency(in); + case QuotationBegin: + case QuotationEnd: { + return macQuotationSymbol(type,in); + } default: break; } @@ -1541,6 +1573,8 @@ Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate) \value PMText a string that represents the system PM designator associated with a 12-hour clock. \value CurrencySymbol a string that represents a currency in a format QLocale::CurrencyFormat. \value FormatCurrency a localized string representation of a number with a currency symbol. + \value QuotationBegin a QString specifying the start of a quotation. the in variant contains a QLocale::QuotationStyle + \value QuotationEnd a QString specifying the end of a quotation. the in variant contains a QLocale::QuotationStyle */ /*! @@ -2328,6 +2362,21 @@ QDataStream &operator>>(QDataStream &ds, QLocale &l) locale specified; otherwise returns false. */ +/*! + \enum QLocale::QuotationStyle + + This enum defines a set of possible styles for locale specific quotation. + + \value StandardQuotation If this option is set, the standard quotation marks + will be used to quote strings. + \value AlternateQuotation If this option is set, the alternate quotation marks + will be used to quote strings. + + \since 4.8 + + \sa quoteString() +*/ + static const int locale_data_size = sizeof(locale_data)/sizeof(QLocalePrivate) - 1; static const QLocalePrivate *dataPointerHelper(quint16 index) @@ -2491,6 +2540,43 @@ QLocale::NumberOptions QLocale::numberOptions() const } /*! + \since 4.8 + + Returns \a str quoted according to the current locale. + + If \a AlternateQuotation is used for \a QuoatationStyle + but the locale does not provide an alternate quotation, + we will fallback to the parent locale. +*/ +QString QLocale::quoteString(const QString &str, QuotationStyle qs) const +{ + + return quoteString(&str, qs); +} + +/*! + \since 4.8 + + \overload +*/ +QString QLocale::quoteString(const QStringRef &str, QuotationStyle qs) const +{ +#ifndef QT_NO_SYSTEMLOCALE + if (d() == systemPrivate()) { + QVariant quotationBegin = systemLocale()->query(QSystemLocale::QuotationBegin, QVariant(qs)); + QVariant quotationEnd = systemLocale()->query(QSystemLocale::QuotationEnd, QVariant(qs)); + if (!quotationBegin.isNull() && !quotationEnd.isNull()) + return quotationBegin.toString() % str % quotationEnd.toString(); + } +#endif + + if (qs == StandardQuotation) + return QChar(d()->m_quotation_start) % str % QChar(d()->m_quotation_end); + else + return QChar(d()->m_alternate_quotation_start) % str % QChar(d()->m_alternate_quotation_end); +} + +/*! \nonreentrant Sets the global default locale to \a locale. These diff --git a/src/corelib/tools/qlocale.h b/src/corelib/tools/qlocale.h index 225ae9cd53..924cb7bc64 100644 --- a/src/corelib/tools/qlocale.h +++ b/src/corelib/tools/qlocale.h @@ -97,7 +97,9 @@ public: PMText, // QString FirstDayOfWeek, // Qt::DayOfWeek CurrencySymbol, // QString in: format - FormatCurrency // QString in: qlonglong, qulonglong or double + FormatCurrency, // QString in: qlonglong, qulonglong or double + QuotationBegin, // QString in: StandardQuotation or AlternateQuotation + QuotationEnd // QString in: StandardQuotation or AlternateQuotation }; virtual QVariant query(QueryType type, QVariant in) const; virtual QLocale fallbackLocale() const; @@ -707,6 +709,10 @@ public: void setNumberOptions(NumberOptions options); NumberOptions numberOptions() const; + enum QuotationStyle { StandardQuotation, AlternateQuotation }; + QString quoteString(const QString &str, QuotationStyle qs = StandardQuotation) const; + QString quoteString(const QStringRef &str, QuotationStyle qs = StandardQuotation) const; + //private: // this should be private, but can't be struct Data { quint16 index; diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index 283f722f91..1d286ab4bc 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -164,6 +164,8 @@ public: quint16 m_decimal, m_group, m_list, m_percent, m_zero, m_minus, m_plus, m_exponential; + quint16 m_quotation_start, m_quotation_end; + quint16 m_alternate_quotation_start, m_alternate_quotation_end; quint16 m_short_date_format_idx, m_short_date_format_size; quint16 m_long_date_format_idx, m_long_date_format_size; |