mirror of
https://bitbucket.org/smil3y/katie.git
synced 2025-02-25 03:12:56 +00:00
check if string is normalized before normalizing it from QString::normalized()
Signed-off-by: Ivailo Monev <xakepa10@laimg.moc>
This commit is contained in:
parent
d236165d11
commit
a30c6c494a
1 changed files with 13 additions and 6 deletions
|
@ -5745,17 +5745,24 @@ QString QString::normalized(QString::NormalizationForm mode, QChar::UnicodeVersi
|
||||||
}
|
}
|
||||||
|
|
||||||
error = U_ZERO_ERROR;
|
error = U_ZERO_ERROR;
|
||||||
const int srcsize = size();
|
const bool normresult = unorm2_isNormalized(normalizer,
|
||||||
QString result(QMAXUSTRLEN(srcsize), Qt::Uninitialized);
|
reinterpret_cast<const UChar*>(unicode()), size(), &error);
|
||||||
|
if (Q_UNLIKELY(U_FAILURE(error))) {
|
||||||
|
qWarning("QString::normalized: unorm2_isNormalized() failed %s", u_errorName(error));
|
||||||
|
return QString();
|
||||||
|
} else if (normresult) {
|
||||||
|
// already normalized
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
error = U_ZERO_ERROR;
|
||||||
|
QString result(QMAXUSTRLEN(size()), Qt::Uninitialized);
|
||||||
const int decresult = unorm2_normalize(normalizer,
|
const int decresult = unorm2_normalize(normalizer,
|
||||||
reinterpret_cast<const UChar*>(unicode()), srcsize,
|
reinterpret_cast<const UChar*>(unicode()), size(),
|
||||||
reinterpret_cast<UChar*>(result.data()), result.size(), &error);
|
reinterpret_cast<UChar*>(result.data()), result.size(), &error);
|
||||||
if (Q_UNLIKELY(U_FAILURE(error))) {
|
if (Q_UNLIKELY(U_FAILURE(error))) {
|
||||||
qWarning("QString::normalized: unorm2_normalize() failed %s", u_errorName(error));
|
qWarning("QString::normalized: unorm2_normalize() failed %s", u_errorName(error));
|
||||||
return QString();
|
return QString();
|
||||||
} else if (Q_UNLIKELY(decresult < 1)) {
|
|
||||||
// no normalization value
|
|
||||||
return *this;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
result.resize(decresult);
|
result.resize(decresult);
|
||||||
|
|
Loading…
Add table
Reference in a new issue