diff options
author | Lars Knoll <lars.knoll@nokia.com> | 2011-07-12 08:22:33 (GMT) |
---|---|---|
committer | Lars Knoll <lars.knoll@nokia.com> | 2011-07-12 09:53:17 (GMT) |
commit | da0e1e101bb4c44c25b6523357fa81ad1b2d6539 (patch) | |
tree | 6867b437b279e74d147c17a71a9789ca2bd5cc54 /src/corelib/tools/qlocale.cpp | |
parent | 693e39f3b630afa44cd1bd8d942825922a5d59fe (diff) | |
download | Qt-da0e1e101bb4c44c25b6523357fa81ad1b2d6539.zip Qt-da0e1e101bb4c44c25b6523357fa81ad1b2d6539.tar.gz Qt-da0e1e101bb4c44c25b6523357fa81ad1b2d6539.tar.bz2 |
Add QLocale::toUpper/Lower
The toUpper/Lower() methods in QString should not
be locale dependent, as this can lead to rather
hard to find bugs in at least a turkish locale.
Rather have explicit, locale dependend case conversions
available in QLocale.
Reviewed-by: Denis Dzyubenko
Diffstat (limited to 'src/corelib/tools/qlocale.cpp')
-rw-r--r-- | src/corelib/tools/qlocale.cpp | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/corelib/tools/qlocale.cpp b/src/corelib/tools/qlocale.cpp index d791529..8640c8b 100644 --- a/src/corelib/tools/qlocale.cpp +++ b/src/corelib/tools/qlocale.cpp @@ -88,6 +88,8 @@ Q_GLOBAL_STATIC(QLocalePrivate, globalLocalePrivate) #ifdef QT_USE_ICU extern bool qt_initIcu(const QString &localeName); +extern bool qt_u_strToUpper(const QString &str, QString *out, const QLocale &locale); +extern bool qt_u_strToLower(const QString &str, QString *out, const QLocale &locale); #endif /****************************************************************************** @@ -2180,6 +2182,42 @@ Qt::LayoutDirection QLocale::textDirection() const return Qt::LeftToRight; } +/*! + \since 4.8 + + Returns an uppercase copy of \a str. +*/ +QString QLocale::toUpper(const QString &str) const +{ +#ifdef QT_USE_ICU + { + QString result; + if (qt_u_strToUpper(str, &result, *this)) + return result; + // else fall through and use Qt's toUpper + } +#endif + return str.toUpper(); +} + +/*! + \since 4.8 + + Returns a lowercase copy of \a str. +*/ +QString QLocale::toLower(const QString &str) const +{ +#ifdef QT_USE_ICU + { + QString result; + if (qt_u_strToLower(str, &result, *this)) + return result; + // else fall through and use Qt's toUpper + } +#endif + return str.toLower(); +} + /*! \since 4.5 |