QStringIterator: port from uint to char32_t

Change-Id: I0ca47b87216478b28e29b0fa1a118ef13b6d7c84
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Reviewed-by: Konstantin Ritt <ritt.ks@gmail.com>
This commit is contained in:
Marc Mutz 2020-04-21 16:30:32 +02:00
parent 19bfcdaa43
commit 4ba25a0920
4 changed files with 25 additions and 27 deletions

View File

@ -62,8 +62,6 @@ QStringIterator i(string); // implicitly converted to QStringView
//! [0] //! [0]
//! [1] //! [1]
// will print 97, 32, 115, 116, etc.;
// that is, the decimal value of the code points in the Unicode string "a string"
while (i.hasNext()) while (i.hasNext())
qDebug() << i.next(); qDebug() << i.next();
//! [1] //! [1]
@ -72,9 +70,9 @@ while (i.hasNext())
{ {
//! [2] //! [2]
QStringIterator i(u"𝄞 is the G clef"); QStringIterator i(u"𝄞 is the G clef");
qDebug() << Qt::hex << i.next(); // will print 1d11e (U+1D11E, MUSICAL SYMBOL G CLEF) qDebug() << Qt::hex << i.next(); // will print '𝄞' (U+1D11E, MUSICAL SYMBOL G CLEF)
qDebug() << Qt::hex << i.next(); // will print 20 (U+0020, SPACE) qDebug() << Qt::hex << i.next(); // will print ' ' (U+0020, SPACE)
qDebug() << Qt::hex << i.next(); // will print 69 (U+0069, LATIN SMALL LETTER I) qDebug() << Qt::hex << i.next(); // will print 'i' (U+0069, LATIN SMALL LETTER I)
//! [2] //! [2]
} }

View File

@ -593,11 +593,11 @@ bool QtPrivate::isLatin1(QStringView s) noexcept
bool QtPrivate::isValidUtf16(QStringView s) noexcept bool QtPrivate::isValidUtf16(QStringView s) noexcept
{ {
Q_CONSTEXPR uint InvalidCodePoint = UINT_MAX; Q_CONSTEXPR char32_t InvalidCodePoint = UINT_MAX;
QStringIterator i(s); QStringIterator i(s);
while (i.hasNext()) { while (i.hasNext()) {
uint c = i.next(InvalidCodePoint); const auto c = i.next(InvalidCodePoint);
if (c == InvalidCodePoint) if (c == InvalidCodePoint)
return false; return false;
} }
@ -5077,7 +5077,7 @@ bool QString::isUpper() const
QStringIterator it(*this); QStringIterator it(*this);
while (it.hasNext()) { while (it.hasNext()) {
uint uc = it.nextUnchecked(); const auto uc = it.nextUnchecked();
if (qGetProp(uc)->cases[QUnicodeTables::UpperCase].diff) if (qGetProp(uc)->cases[QUnicodeTables::UpperCase].diff)
return false; return false;
} }
@ -5103,7 +5103,7 @@ bool QString::isLower() const
QStringIterator it(*this); QStringIterator it(*this);
while (it.hasNext()) { while (it.hasNext()) {
uint uc = it.nextUnchecked(); const auto uc = it.nextUnchecked();
if (qGetProp(uc)->cases[QUnicodeTables::LowerCase].diff) if (qGetProp(uc)->cases[QUnicodeTables::LowerCase].diff)
return false; return false;
} }
@ -6546,7 +6546,7 @@ static QString detachAndConvertCase(T &str, QStringIterator it, QUnicodeTables::
QChar *pp = s.begin() + it.index(); // will detach if necessary QChar *pp = s.begin() + it.index(); // will detach if necessary
do { do {
uint uc = it.nextUnchecked(); auto uc = it.nextUnchecked();
const auto fold = qGetProp(uc)->cases[which]; const auto fold = qGetProp(uc)->cases[which];
signed short caseDiff = fold.diff; signed short caseDiff = fold.diff;
@ -6594,7 +6594,7 @@ static QString convertCase(T &str, QUnicodeTables::Case which)
QStringIterator it(p, e); QStringIterator it(p, e);
while (it.hasNext()) { while (it.hasNext()) {
uint uc = it.nextUnchecked(); const auto uc = it.nextUnchecked();
if (qGetProp(uc)->cases[which].diff) { if (qGetProp(uc)->cases[which].diff) {
it.recedeUnchecked(); it.recedeUnchecked();
return detachAndConvertCase(str, it, which); return detachAndConvertCase(str, it, which);

View File

@ -170,7 +170,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::peekNextUnchecked() const \fn QStringIterator::peekNextUnchecked() const
Returns the Unicode code point that is immediately after the iterator's current Returns the Unicode code point that is immediately after the iterator's current
position. The current position is not changed. position. The current position is not changed.
@ -182,7 +182,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::peekNext(uint invalidAs = QChar::ReplacementCharacter) const \fn QStringIterator::peekNext(char32_t invalidAs = QChar::ReplacementCharacter) const
Returns the Unicode code point that is immediately after the iterator's current Returns the Unicode code point that is immediately after the iterator's current
position. The current position is not changed. position. The current position is not changed.
@ -198,7 +198,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::nextUnchecked() \fn QStringIterator::nextUnchecked()
Advances the iterator's current position by one Unicode code point, Advances the iterator's current position by one Unicode code point,
and returns the Unicode code point that gets pointed by the iterator. and returns the Unicode code point that gets pointed by the iterator.
@ -210,7 +210,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::next(uint invalidAs = QChar::ReplacementCharacter) \fn QStringIterator::next(char32_t invalidAs = QChar::ReplacementCharacter)
Advances the iterator's current position by one Unicode code point, Advances the iterator's current position by one Unicode code point,
and returns the Unicode code point that gets pointed by the iterator. and returns the Unicode code point that gets pointed by the iterator.
@ -258,7 +258,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::peekPreviousUnchecked() const \fn QStringIterator::peekPreviousUnchecked() const
Returns the Unicode code point that is immediately before the iterator's current Returns the Unicode code point that is immediately before the iterator's current
position. The current position is not changed. position. The current position is not changed.
@ -270,7 +270,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::peekPrevious(uint invalidAs = QChar::ReplacementCharacter) const \fn QStringIterator::peekPrevious(char32_t invalidAs = QChar::ReplacementCharacter) const
Returns the Unicode code point that is immediately before the iterator's current Returns the Unicode code point that is immediately before the iterator's current
position. The current position is not changed. position. The current position is not changed.
@ -286,7 +286,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::previousUnchecked() \fn QStringIterator::previousUnchecked()
Moves the iterator's current position back by one Unicode code point, Moves the iterator's current position back by one Unicode code point,
and returns the Unicode code point that gets pointed by the iterator. and returns the Unicode code point that gets pointed by the iterator.
@ -298,7 +298,7 @@
*/ */
/*! /*!
\fn uint QStringIterator::previous(uint invalidAs = QChar::ReplacementCharacter) \fn QStringIterator::previous(char32_t invalidAs = QChar::ReplacementCharacter)
Moves the iterator's current position back by one Unicode code point, Moves the iterator's current position back by one Unicode code point,
and returns the Unicode code point that gets pointed by the iterator. and returns the Unicode code point that gets pointed by the iterator.

View File

@ -124,7 +124,7 @@ public:
++pos; ++pos;
} }
inline uint peekNextUnchecked() const inline char32_t peekNextUnchecked() const
{ {
Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item"); Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item");
@ -134,7 +134,7 @@ public:
return pos->unicode(); return pos->unicode();
} }
inline uint peekNext(uint invalidAs = QChar::ReplacementCharacter) const inline char32_t peekNext(char32_t invalidAs = QChar::ReplacementCharacter) const
{ {
Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item"); Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item");
@ -150,7 +150,7 @@ public:
return pos->unicode(); return pos->unicode();
} }
inline uint nextUnchecked() inline char32_t nextUnchecked()
{ {
Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item"); Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item");
@ -160,7 +160,7 @@ public:
return cur.unicode(); return cur.unicode();
} }
inline uint next(uint invalidAs = QChar::ReplacementCharacter) inline char32_t next(char32_t invalidAs = QChar::ReplacementCharacter)
{ {
Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item"); Q_ASSERT_X(hasNext(), Q_FUNC_INFO, "iterator hasn't a next item");
@ -200,7 +200,7 @@ public:
--pos; --pos;
} }
inline uint peekPreviousUnchecked() const inline char32_t peekPreviousUnchecked() const
{ {
Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item"); Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item");
@ -209,7 +209,7 @@ public:
return pos[-1].unicode(); return pos[-1].unicode();
} }
inline uint peekPrevious(uint invalidAs = QChar::ReplacementCharacter) const inline char32_t peekPrevious(char32_t invalidAs = QChar::ReplacementCharacter) const
{ {
Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item"); Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item");
@ -225,7 +225,7 @@ public:
return pos[-1].unicode(); return pos[-1].unicode();
} }
inline uint previousUnchecked() inline char32_t previousUnchecked()
{ {
Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item"); Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item");
@ -235,7 +235,7 @@ public:
return cur.unicode(); return cur.unicode();
} }
inline uint previous(uint invalidAs = QChar::ReplacementCharacter) inline char32_t previous(char32_t invalidAs = QChar::ReplacementCharacter)
{ {
Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item"); Q_ASSERT_X(hasPrevious(), Q_FUNC_INFO, "iterator hasn't a previous item");