From 97e177e58d195f78ac103b3dd0b8ecedb1e07d4c Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 1 Jun 2012 17:51:06 +0200 Subject: Refactor the ICU code for QLocale Clean up the ICU code and make it thread-safe. Add a QIcuData structure to QLocalePrivate, that contains ICU specific data. Link against ICU directly, greatly simplifying the code. Also fix a bug in the locale specific case conversion code that would cause it to fail and fall back to the QString code if the output string was larger than the input. Change-Id: Ie67e5ea14fa204ebc5887d7aaeb1a4f3ecaf8697 Reviewed-by: Thiago Macieira --- src/corelib/tools/qlocale_p.h | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/corelib/tools/qlocale_p.h') diff --git a/src/corelib/tools/qlocale_p.h b/src/corelib/tools/qlocale_p.h index c2c1488966..1902e4e5af 100644 --- a/src/corelib/tools/qlocale_p.h +++ b/src/corelib/tools/qlocale_p.h @@ -126,6 +126,16 @@ private: }; #endif +#ifdef QT_USE_ICU +namespace QIcu { + QString toUpper(const QByteArray &localeId, const QString &str, bool *ok); + QString toLower(const QByteArray &localeId, const QString &str, bool *ok); + + bool strcoll(const QByteArray &localeID, const QChar *source, int sourceLength, const QChar *target, int targetLength, int *result); +} +#endif + + struct QLocaleData { public: @@ -178,7 +188,17 @@ public: class Q_CORE_EXPORT QLocalePrivate : public QSharedData { public: - QLocalePrivate() : m_index(0), m_numberOptions(0), m_data(0) {} + QLocalePrivate(int index, int numberOptions = 0) + : m_index(index), m_numberOptions(numberOptions) + { + m_data = dataPointerForIndex(index); + m_localeID = bcp47Name().toLatin1(); + m_localeID.replace('-','_'); + } + + ~QLocalePrivate() + { + } QChar decimal() const { return QChar(m_data->m_decimal); } QChar group() const { return QChar(m_data->m_group); } @@ -203,6 +223,7 @@ public: static QLocale::Country codeToCountry(const QString &code); static void getLangAndCountry(const QString &name, QLocale::Language &lang, QLocale::Script &script, QLocale::Country &cntry); + static const QLocaleData *dataPointerForIndex(quint16 index); QLocale::MeasurementSystem measurementSystem() const; @@ -285,11 +306,11 @@ public: QString dateTimeToString(const QString &format, const QDate *date, const QTime *time, const QLocale *q) const; -private: friend class QLocale; quint16 m_index; quint16 m_numberOptions; const QLocaleData *m_data; + QByteArray m_localeID; }; inline char QLocalePrivate::digitToCLocale(QChar in) const -- cgit v1.2.3