1
/****************************************************************************
3
** Copyright (C) 2016 The Qt Company Ltd.
4
** Contact: https://www.qt.io/licensing/
6
** This file is part of the documentation of the Qt Toolkit.
8
** $QT_BEGIN_LICENSE:BSD$
9
** Commercial License Usage
10
** Licensees holding valid commercial Qt licenses may use this file in
11
** accordance with the commercial license agreement provided with the
12
** Software or, alternatively, in accordance with the terms contained in
13
** a written agreement between you and The Qt Company. For licensing terms
14
** and conditions see https://www.qt.io/terms-conditions. For further
15
** information use the contact form at https://www.qt.io/contact-us.
18
** Alternatively, you may use this file under the terms of the BSD license
21
** "Redistribution and use in source and binary forms, with or without
22
** modification, are permitted provided that the following conditions are
24
** * Redistributions of source code must retain the above copyright
25
** notice, this list of conditions and the following disclaimer.
26
** * Redistributions in binary form must reproduce the above copyright
27
** notice, this list of conditions and the following disclaimer in
28
** the documentation and/or other materials provided with the
30
** * Neither the name of The Qt Company Ltd nor the names of its
31
** contributors may be used to endorse or promote products derived
32
** from this software without specific prior written permission.
35
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
36
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
37
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
38
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
39
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
40
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
41
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
42
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
43
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
44
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
45
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
49
****************************************************************************/
53
list << "one" << "two" << "three";
55
qFill(list.begin(), list.end(), "eleven");
56
// list: [ "eleven", "eleven", "eleven" ]
61
qFill(list.begin() + 1, list.end(), "six");
62
// list: [ "eleven", "six", "six" ]
67
QChar resolveEntity(const QString &entity)
69
static const QLatin1String name_table[] = {
70
"AElig", "Aacute", ..., "zwnj"
72
static const ushort value_table[] = {
73
0x0061, 0x00c1, ..., 0x200c
75
int N = sizeof(name_table) / sizeof(name_table[0]);
77
const QLatin1String *name = qBinaryFind(name_table, name_table + N,
79
int index = name - name_table;
83
return QChar(value_table[index]);
89
QChar resolveEntity(const QString &entity)
91
static QMap<QString, int> entityMap;
94
entityMap.insert("AElig", 0x0061);
95
entityMap.insert("Aacute", 0x00c1);
97
entityMap.insert("zwnj", 0x200c);
99
return QChar(entityMap.value(entity));
106
list << "one" << "two" << "three";
108
QVector<QString> vect1(3);
109
qCopy(list.begin(), list.end(), vect1.begin());
110
// vect: [ "one", "two", "three" ]
112
QVector<QString> vect2(8);
113
qCopy(list.begin(), list.end(), vect2.begin() + 2);
114
// vect: [ "", "", "one", "two", "three", "", "", "" ]
120
list << "one" << "two" << "three";
122
QVector<QString> vect(5);
123
qCopyBackward(list.begin(), list.end(), vect.end());
124
// vect: [ "", "", "one", "two", "three" ]
130
list << "one" << "two" << "three";
132
QVector<QString> vect(3);
137
bool ret1 = qEqual(list.begin(), list.end(), vect.begin());
141
bool ret2 = qEqual(list.begin(), list.end(), vect.begin());
148
list << "one" << "two" << "three";
150
qFill(list.begin(), list.end(), "eleven");
151
// list: [ "eleven", "eleven", "eleven" ]
153
qFill(list.begin() + 1, list.end(), "six");
154
// list: [ "eleven", "six", "six" ]
160
list << "one" << "two" << "three";
162
QStringList::iterator i1 = qFind(list.begin(), list.end(), "two");
163
// i1 == list.begin() + 1
165
QStringList::iterator i2 = qFind(list.begin(), list.end(), "seventy");
172
list << 3 << 3 << 6 << 6 << 6 << 8;
175
qCount(list.begin(), list.end(), 6, countOf6);
179
qCount(list.begin(), list.end(), 7, countOf7);
189
// pi == 2.71, e == 3.14
195
list << 33 << 12 << 68 << 6 << 12;
196
qSort(list.begin(), list.end());
197
// list: [ 6, 12, 12, 33, 68 ]
202
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
204
return s1.toLower() < s2.toLower();
210
list << "AlPha" << "beTA" << "gamma" << "DELTA";
211
qSort(list.begin(), list.end(), caseInsensitiveLessThan);
212
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
219
list << 33 << 12 << 68 << 6 << 12;
220
qSort(list.begin(), list.end(), qGreater<int>());
221
// list: [ 68, 33, 12, 12, 6 ]
227
list << "AlPha" << "beTA" << "gamma" << "DELTA";
229
QMap<QString, QString> map;
230
foreach (const QString &str, list)
231
map.insert(str.toLower(), str);
239
list << 33 << 12 << 68 << 6 << 12;
240
qStableSort(list.begin(), list.end());
241
// list: [ 6, 12, 12, 33, 68 ]
246
bool caseInsensitiveLessThan(const QString &s1, const QString &s2)
248
return s1.toLower() < s2.toLower();
254
list << "AlPha" << "beTA" << "gamma" << "DELTA";
255
qStableSort(list.begin(), list.end(), caseInsensitiveLessThan);
256
// list: [ "AlPha", "beTA", "DELTA", "gamma" ]
263
list << 33 << 12 << 68 << 6 << 12;
264
qStableSort(list.begin(), list.end(), qGreater<int>());
265
// list: [ 68, 33, 12, 12, 6 ]
271
list << 3 << 3 << 6 << 6 << 6 << 8;
273
QList<int>::iterator i = qLowerBound(list.begin(), list.end(), 5);
275
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
277
i = qLowerBound(list.begin(), list.end(), 12);
279
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
285
vect << 3 << 3 << 6 << 6 << 6 << 8;
286
QVector<int>::iterator begin6 =
287
qLowerBound(vect.begin(), vect.end(), 6);
288
QVector<int>::iterator end6 =
289
qUpperBound(begin6, vect.end(), 6);
291
QVector<int>::iterator i = begin6;
296
// vect: [ 3, 3, 7, 7, 7, 8 ]
302
list << 3 << 3 << 6 << 6 << 6 << 8;
304
QList<int>::iterator i = qUpperBound(list.begin(), list.end(), 5);
306
// list: [ 3, 3, 5, 6, 6, 6, 8 ]
308
i = qUpperBound(list.begin(), list.end(), 12);
310
// list: [ 3, 3, 5, 6, 6, 6, 8, 12 ]
316
vect << 3 << 3 << 6 << 6 << 6 << 8;
317
QVector<int>::iterator begin6 =
318
qLowerBound(vect.begin(), vect.end(), 6);
319
QVector<int>::iterator end6 =
320
qUpperBound(vect.begin(), vect.end(), 6);
322
QVector<int>::iterator i = begin6;
327
// vect: [ 3, 3, 7, 7, 7, 8 ]
333
vect << 3 << 3 << 6 << 6 << 6 << 8;
335
QVector<int>::iterator i =
336
qBinaryFind(vect.begin(), vect.end(), 6);
337
// i == vect.begin() + 2 (or 3 or 4)
342
QList<Employee *> list;
343
list.append(new Employee("Blackpool", "Stephen"));
344
list.append(new Employee("Twist", "Oliver"));
346
qDeleteAll(list.begin(), list.end());
353
list << 33 << 12 << 68 << 6 << 12;
354
qSort(list.begin(), list.end(), qLess<int>());
355
// list: [ 6, 12, 12, 33, 68 ]
361
list << 33 << 12 << 68 << 6 << 12;
362
qSort(list.begin(), list.end(), qGreater<int>());
363
// list: [ 68, 33, 12, 12, 6 ]