本文整理汇总了C++中QString::cbegin方法的典型用法代码示例。如果您正苦于以下问题:C++ QString::cbegin方法的具体用法?C++ QString::cbegin怎么用?C++ QString::cbegin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QString
的用法示例。
在下文中一共展示了QString::cbegin方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1:
bool OsmAnd::Utilities::extractFirstNumberPosition(const QString& value, int& first, int& last, bool allowSigned, bool allowDot)
{
first = -1;
last = -1;
int curPos = 0;
for(auto itChr = value.cbegin(); itChr != value.cend() && (first == -1 || last == -1); ++itChr, curPos++)
{
auto chr = *itChr;
if (first == -1 && chr.isDigit())
first = curPos;
if (last == -1 && first != -1 && !chr.isDigit() && ((allowDot && chr != '.') || !allowDot))
last = curPos - 1;
}
if (first >= 1 && allowSigned && value[first - 1] == '-')
first -= 1;
if (first != -1 && last == -1)
last = value.length() - 1;
return first != -1;
}
示例2: constIteratorRandomAccessIteratorRequirementsTest
void StringIteratorTest::constIteratorRandomAccessIteratorRequirementsTest()
{
const QString str = "ABCDEF";
const StringConstIterator first = str.cbegin();
StringConstIterator it;
StringConstIterator::difference_type n;
/*
* it + n
*/
n = 1;
it = first + n;
QCOMPARE(*it, wchar_t('B'));
n = 2;
it = n + first;
QCOMPARE(*it, wchar_t('C'));
/*
* b - a
*/
StringConstIterator a, b;
a = first + 1;
b = first + 3;
n = b - a;
QVERIFY( n == 2 );
}
示例3: constIteratorTest
void StringIteratorTest::constIteratorTest()
{
const QString str = "ABCDEF";
/*
* Constructs and assignements
*/
// Direct assignement
StringConstIterator it(str.cbegin());
QCOMPARE(*it, wchar_t('A'));
// Default constructed
StringConstIterator first, last;
// Assignement
first = str.cbegin();
QCOMPARE(*first, wchar_t('A'));
last = first;
QCOMPARE(*last, wchar_t('A'));
/*
* Increment
*/
it = str.cbegin();
QCOMPARE(*it, wchar_t('A'));
// Pre-increment
++it;
QCOMPARE(*it, wchar_t('B'));
// Post-increment
QCOMPARE(*it++, wchar_t('B'));
QCOMPARE(*it, wchar_t('C'));
/*
* Decrement
*/
it = str.cbegin();
QCOMPARE(*it, wchar_t('A'));
++it;
++it;
QCOMPARE(*it, wchar_t('C'));
// Pre-decrement
--it;
QCOMPARE(*it, wchar_t('B'));
// Post-decrement
QCOMPARE(*it--, wchar_t('B'));
QCOMPARE(*it, wchar_t('A'));
/*
* Increment and decrement by n
*/
it = str.cbegin();
QCOMPARE(*it, wchar_t('A'));
it += 2;
QCOMPARE(*it, wchar_t('C'));
it -= 2;
QCOMPARE(*it, wchar_t('A'));
first = it;
it = first + 2;
QCOMPARE(*it, wchar_t('C'));
first = it - 1;
QCOMPARE(*first, wchar_t('B'));
/*
* Index based access
*/
it = str.cbegin();
QCOMPARE(it[0], wchar_t('A'));
QCOMPARE(it[1], wchar_t('B'));
QCOMPARE(it[2], wchar_t('C'));
/*
* Comparisons
*/
first = str.cbegin();
it = first;
QVERIFY(it == first);
QVERIFY(!(it != first));
QVERIFY(!(it < first));
QVERIFY(it <= first);
QVERIFY(!(it > first));
QVERIFY(it >= first);
// Increment it and check
++it;
QVERIFY(!(it == first));
QVERIFY(it != first);
QVERIFY(!(it < first));
QVERIFY(!(it <= first));
QVERIFY(it > first);
QVERIFY(it >= first);
}