tools/qstringbuilder.cpp

Source codeSwitch to Preprocessed file
LineSource CodeCoverage
1/**************************************************************************** -
2** -
3** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). -
4** Contact: http://www.qt-project.org/legal -
5** -
6** This file is part of the QtCore module of the Qt Toolkit. -
7** -
8** $QT_BEGIN_LICENSE:LGPL$ -
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 Digia. For licensing terms and -
14** conditions see http://qt.digia.com/licensing. For further information -
15** use the contact form at http://qt.digia.com/contact-us. -
16** -
17** GNU Lesser General Public License Usage -
18** Alternatively, this file may be used under the terms of the GNU Lesser -
19** General Public License version 2.1 as published by the Free Software -
20** Foundation and appearing in the file LICENSE.LGPL included in the -
21** packaging of this file. Please review the following information to -
22** ensure the GNU Lesser General Public License version 2.1 requirements -
23** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. -
24** -
25** In addition, as a special exception, Digia gives you certain additional -
26** rights. These rights are described in the Digia Qt LGPL Exception -
27** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. -
28** -
29** GNU General Public License Usage -
30** Alternatively, this file may be used under the terms of the GNU -
31** General Public License version 3.0 as published by the Free Software -
32** Foundation and appearing in the file LICENSE.GPL included in the -
33** packaging of this file. Please review the following information to -
34** ensure the GNU General Public License version 3.0 requirements will be -
35** met: http://www.gnu.org/copyleft/gpl.html. -
36** -
37** -
38** $QT_END_LICENSE$ -
39** -
40****************************************************************************/ -
41 -
42#include "qstringbuilder.h" -
43#include <QtCore/qtextcodec.h> -
44 -
45QT_BEGIN_NAMESPACE -
46 -
47/*! -
48 \class QStringBuilder -
49 \inmodule QtCore -
50 \internal -
51 \reentrant -
52 \since 4.6 -
53 -
54 \brief The QStringBuilder class is a template class that provides a facility to build up QStrings from smaller chunks. -
55 -
56 \ingroup tools -
57 \ingroup shared -
58 \ingroup string-processing -
59 -
60 -
61 To build a QString by multiple concatenations, QString::operator+() -
62 is typically used. This causes \e{n - 1} reallocations when building -
63 a string from \e{n} chunks. -
64 -
65 QStringBuilder uses expression templates to collect the individual -
66 chunks, compute the total size, allocate the required amount of -
67 memory for the final QString object, and copy the chunks into the -
68 allocated memory. -
69 -
70 The QStringBuilder class is not to be used explicitly in user -
71 code. Instances of the class are created as return values of the -
72 operator%() function, acting on objects of type QString, -
73 QLatin1String, QStringRef, QChar, QCharRef, -
74 QLatin1Char, and \c char. -
75 -
76 Concatenating strings with operator%() generally yields better -
77 performance then using \c QString::operator+() on the same chunks -
78 if there are three or more of them, and performs equally well in other -
79 cases. -
80 -
81 \sa QLatin1String, QString -
82*/ -
83 -
84/*! \fn QStringBuilder::QStringBuilder(const A &a, const B &b) -
85 Constructs a QStringBuilder from \a a and \a b. -
86 */ -
87 -
88/* \fn QStringBuilder::operator%(const A &a, const B &b) -
89 -
90 Returns a \c QStringBuilder object that is converted to a QString object -
91 when assigned to a variable of QString type or passed to a function that -
92 takes a QString parameter. -
93 -
94 This function is usable with arguments of type \c QString, -
95 \c QLatin1String, \c QStringRef, -
96 \c QChar, \c QCharRef, \c QLatin1Char, and \c char. -
97*/ -
98 -
99/* \fn QByteArray QStringBuilder::toLatin1() const -
100 Returns a Latin-1 representation of the string as a QByteArray. The -
101 returned byte array is undefined if the string contains non-Latin1 -
102 characters. -
103 */ -
104/* \fn QByteArray QStringBuilder::toUtf8() const -
105 Returns a UTF-8 representation of the string as a QByteArray. -
106 */ -
107 -
108 -
109/*! -
110 \internal -
111 */ -
112void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) -
113{ -
114 if (len == -1) {
evaluated: len == -1
TRUEFALSE
yes
Evaluation Count:8
yes
Evaluation Count:274
8-274
115 if (!a)
evaluated: !a
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:4
4
116 return;
executed: return;
Execution Count:4
4
117 while (*a && uchar(*a) < 0x80U)
evaluated: *a
TRUEFALSE
yes
Evaluation Count:4
yes
Evaluation Count:3
evaluated: uchar(*a) < 0x80U
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-4
118 *out++ = QLatin1Char(*a++);
executed: *out++ = QLatin1Char(*a++);
Execution Count:3
3
119 if (!*a)
evaluated: !*a
TRUEFALSE
yes
Evaluation Count:3
yes
Evaluation Count:1
1-3
120 return;
executed: return;
Execution Count:3
3
121 } else {
executed: }
Execution Count:1
1
122 int i;
executed (the execution status of this line is deduced): int i;
-
123 for (i = 0; i < len && uchar(a[i]) < 0x80U; ++i)
evaluated: i < len
TRUEFALSE
yes
Evaluation Count:1388
yes
Evaluation Count:258
evaluated: uchar(a[i]) < 0x80U
TRUEFALSE
yes
Evaluation Count:1372
yes
Evaluation Count:16
16-1388
124 *out++ = QLatin1Char(a[i]);
executed: *out++ = QLatin1Char(a[i]);
Execution Count:1372
1372
125 if (i == len)
evaluated: i == len
TRUEFALSE
yes
Evaluation Count:258
yes
Evaluation Count:16
16-258
126 return;
executed: return;
Execution Count:258
258
127 a += i;
executed (the execution status of this line is deduced): a += i;
-
128 len -= i;
executed (the execution status of this line is deduced): len -= i;
-
129 }
executed: }
Execution Count:16
16
130 -
131 // we need to complement with UTF-8 appending -
132 QString tmp = QString::fromUtf8(a, len);
executed (the execution status of this line is deduced): QString tmp = QString::fromUtf8(a, len);
-
133 memcpy(out, reinterpret_cast<const char *>(tmp.constData()), sizeof(QChar) * tmp.size());
executed (the execution status of this line is deduced): memcpy(out, reinterpret_cast<const char *>(tmp.constData()), sizeof(QChar) * tmp.size());
-
134 out += tmp.size();
executed (the execution status of this line is deduced): out += tmp.size();
-
135}
executed: }
Execution Count:17
17
136 -
137QT_END_NAMESPACE -
138 -
Source codeSwitch to Preprocessed file

Generated by Squish Coco Non-Commercial