qstringbuilder.cpp

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

Generated by Squish Coco Non-Commercial 4.3.0-BETA-master-30-08-2018-4cb69e9