mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-24 10:52:56 +00:00
use ICU functions to convert QString to lower/upper/case folded string
fixes string comparison in some cases Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
parent
fee87277bc
commit
c48faa7d51
1 changed files with 24 additions and 12 deletions
|
@ -4469,11 +4469,15 @@ QString QString::toLower() const
|
|||
if (!d->data || !d->size)
|
||||
return *this;
|
||||
|
||||
QString result(d->size, Qt::Uninitialized);
|
||||
for (int i = 0; i < d->size; i++) {
|
||||
result.d->data[i] = QChar::toLower(d->data[i]);
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
const int maxchars = d->size + 1; // ICU will write zero-terminator
|
||||
UChar result[maxchars];
|
||||
const int lowerresult = u_strToLower(result, maxchars,
|
||||
reinterpret_cast<const UChar*>(d->data), d->size, "C", &error);
|
||||
if (Q_UNLIKELY(lowerresult > maxchars || U_FAILURE(error))) {
|
||||
return QString();
|
||||
}
|
||||
return result;
|
||||
return QString(reinterpret_cast<QChar*>(result), lowerresult);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -4485,11 +4489,15 @@ QString QString::toCaseFolded() const
|
|||
if (!d->data || !d->size)
|
||||
return *this;
|
||||
|
||||
QString result(d->size, Qt::Uninitialized);
|
||||
for (int i = 0; i < d->size; i++) {
|
||||
result.d->data[i] = QChar::toCaseFolded(d->data[i]);
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
const int maxchars = d->size + 1; // ICU will write zero-terminator
|
||||
UChar result[maxchars];
|
||||
const int foldresult = u_strFoldCase(result, maxchars,
|
||||
reinterpret_cast<const UChar*>(d->data), d->size, U_FOLD_CASE_DEFAULT, &error);
|
||||
if (Q_UNLIKELY(foldresult > maxchars || U_FAILURE(error))) {
|
||||
return QString();
|
||||
}
|
||||
return result;
|
||||
return QString(reinterpret_cast<QChar*>(result), foldresult);
|
||||
}
|
||||
|
||||
/*!
|
||||
|
@ -4508,11 +4516,15 @@ QString QString::toUpper() const
|
|||
if (!d->data || !d->size)
|
||||
return *this;
|
||||
|
||||
QString result(d->size, Qt::Uninitialized);
|
||||
for (int i = 0; i < d->size; i++) {
|
||||
result.d->data[i] = QChar::toUpper(d->data[i]);
|
||||
UErrorCode error = U_ZERO_ERROR;
|
||||
const int maxchars = d->size + 1; // ICU will write zero-terminator
|
||||
UChar result[maxchars];
|
||||
const int upperresult = u_strToUpper(result, maxchars,
|
||||
reinterpret_cast<const UChar*>(d->data), d->size, "C", &error);
|
||||
if (Q_UNLIKELY(upperresult > maxchars || U_FAILURE(error))) {
|
||||
return QString();
|
||||
}
|
||||
return result;
|
||||
return QString(reinterpret_cast<QChar*>(result), upperresult);
|
||||
}
|
||||
|
||||
// ### Qt 5: Consider whether this function shouldn't be removed See task 202871.
|
||||
|
|
Loading…
Add table
Reference in a new issue