summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-12-16 20:09:25 +0100
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2020-01-11 19:28:50 +0100
commit577d698b8e72bc0969ae7545a1a56d3a3d08bdda (patch)
treece87b65fa7891e20248b1ad939dca5feb4e2970b /src/corelib
parentc584380c6901b1bcd9f8100fa1087b09d3cb023d (diff)
QString::isLower/isUpper: redo the implementation
Use QStringIterator rather than indexed loops. This fixes handling of non-BMP code points (which may be lower or uppercase, see the test). Change also the semantics of the functions, adopting Unicode ยง3.13 definitions: a string is lowercase/uppercase if it's equal to its own toLower/toUpper folding. As a side effect, empty strings are now correctly reported to be lowercase AND uppercase. [ChangeLog][Important Behavior Changes] The semantics of QString::isLower() and QString::isUpper() have been changed to match the Unicode specification. Now lowercase (resp. uppercase) strings are allowed to contain any character; a string is considered lowercase (resp. uppercase) if it's equal to its own toLower() (resp. toUpper()) folding. Previously, a non-letter character would make the string not lowercase nor uppercase, and the mere presence of an uppercase (resp. lowercase) letter would make isLower() (resp. isUpper()) return false, even if the letter wouldn't change under case folding. As a consequence, now empty strings are lowercase and uppercase. [ChangeLog][QtCore][QString] Fixed a number of bugs of QString::isLower() and QString::isUpper(). Empty strings are now correctly reported to be lowercase (resp. uppercase), and strings containing code points outside the BMP are now correctly handled. Note that the behavior of these functions has also been changed. Change-Id: Iba1398279a072399a9f21295fe75f6e414f3f813 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/text/qstring.cpp44
1 files changed, 26 insertions, 18 deletions
diff --git a/src/corelib/text/qstring.cpp b/src/corelib/text/qstring.cpp
index b929786255..fa8b5cf3f8 100644
--- a/src/corelib/text/qstring.cpp
+++ b/src/corelib/text/qstring.cpp
@@ -5109,21 +5109,25 @@ bool QString::endsWith(QChar c, Qt::CaseSensitivity cs) const
}
/*!
- Returns \c true if the string only contains uppercase letters,
- otherwise returns \c false.
+ Returns \c true if the string is uppercase, that is, it's identical
+ to its toUpper() folding.
+
+ Note that this does \e not mean that the string does not contain
+ lowercase letters (some lowercase letters do not have a uppercase
+ folding; they are left unchanged by toUpper()).
+ For more information, refer to the Unicode standard, section 3.13.
+
\since 5.12
- \sa QChar::isUpper(), isLower()
+ \sa QChar::toUpper(), isLower()
*/
bool QString::isUpper() const
{
- if (isEmpty())
- return false;
+ QStringIterator it(*this);
- const QChar *d = data();
-
- for (int i = 0, max = size(); i < max; ++i) {
- if (!d[i].isUpper())
+ while (it.hasNext()) {
+ uint uc = it.nextUnchecked();
+ if (qGetProp(uc)->cases[QUnicodeTables::UpperCase].diff)
return false;
}
@@ -5131,21 +5135,25 @@ bool QString::isUpper() const
}
/*!
- Returns \c true if the string only contains lowercase letters,
- otherwise returns \c false.
+ Returns \c true if the string is lowercase, that is, it's identical
+ to its toLower() folding.
+
+ Note that this does \e not mean that the string does not contain
+ uppercase letters (some uppercase letters do not have a lowercase
+ folding; they are left unchanged by toLower()).
+ For more information, refer to the Unicode standard, section 3.13.
+
\since 5.12
- \sa QChar::isLower(), isUpper()
+ \sa QChar::toLower(), isUpper()
*/
bool QString::isLower() const
{
- if (isEmpty())
- return false;
+ QStringIterator it(*this);
- const QChar *d = data();
-
- for (int i = 0, max = size(); i < max; ++i) {
- if (!d[i].isLower())
+ while (it.hasNext()) {
+ uint uc = it.nextUnchecked();
+ if (qGetProp(uc)->cases[QUnicodeTables::LowerCase].diff)
return false;
}