| Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/tools/qstringbuilder.cpp |
| Source code | Switch to Preprocessed file |
| Line | Source | Count | ||||||
|---|---|---|---|---|---|---|---|---|
| 1 | /**************************************************************************** | - | ||||||
| 2 | ** | - | ||||||
| 3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||
| 4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||
| 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 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. | - | ||||||
| 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 3 as published by the Free Software | - | ||||||
| 20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||
| 21 | ** packaging of this file. Please review the following information to | - | ||||||
| 22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||
| 23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||
| 24 | ** | - | ||||||
| 25 | ** GNU General Public License Usage | - | ||||||
| 26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||
| 27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||
| 28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||
| 29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||
| 30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||
| 31 | ** included in the packaging of this file. Please review the following | - | ||||||
| 32 | ** information to ensure the GNU General Public License requirements will | - | ||||||
| 33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||
| 34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||
| 35 | ** | - | ||||||
| 36 | ** $QT_END_LICENSE$ | - | ||||||
| 37 | ** | - | ||||||
| 38 | ****************************************************************************/ | - | ||||||
| 39 | - | |||||||
| 40 | #include "qstringbuilder.h" | - | ||||||
| 41 | #include <QtCore/qtextcodec.h> | - | ||||||
| 42 | #include <private/qutfcodec_p.h> | - | ||||||
| 43 | - | |||||||
| 44 | QT_BEGIN_NAMESPACE | - | ||||||
| 45 | - | |||||||
| 46 | /*! | - | ||||||
| 47 | \class QStringBuilder | - | ||||||
| 48 | \inmodule QtCore | - | ||||||
| 49 | \internal | - | ||||||
| 50 | \reentrant | - | ||||||
| 51 | \since 4.6 | - | ||||||
| 52 | - | |||||||
| 53 | \brief The QStringBuilder class is a template class that provides a facility to build up QStrings from smaller chunks. | - | ||||||
| 54 | - | |||||||
| 55 | \ingroup tools | - | ||||||
| 56 | \ingroup shared | - | ||||||
| 57 | \ingroup string-processing | - | ||||||
| 58 | - | |||||||
| 59 | - | |||||||
| 60 | To build a QString by multiple concatenations, QString::operator+() | - | ||||||
| 61 | is typically used. This causes \e{n - 1} reallocations when building | - | ||||||
| 62 | a string from \e{n} chunks. | - | ||||||
| 63 | - | |||||||
| 64 | QStringBuilder uses expression templates to collect the individual | - | ||||||
| 65 | chunks, compute the total size, allocate the required amount of | - | ||||||
| 66 | memory for the final QString object, and copy the chunks into the | - | ||||||
| 67 | allocated memory. | - | ||||||
| 68 | - | |||||||
| 69 | The QStringBuilder class is not to be used explicitly in user | - | ||||||
| 70 | code. Instances of the class are created as return values of the | - | ||||||
| 71 | operator%() function, acting on objects of type QString, | - | ||||||
| 72 | QLatin1String, QStringRef, QChar, QCharRef, | - | ||||||
| 73 | QLatin1Char, and \c char. | - | ||||||
| 74 | - | |||||||
| 75 | Concatenating strings with operator%() generally yields better | - | ||||||
| 76 | performance then using \c QString::operator+() on the same chunks | - | ||||||
| 77 | if there are three or more of them, and performs equally well in other | - | ||||||
| 78 | cases. | - | ||||||
| 79 | - | |||||||
| 80 | \sa QLatin1String, QString | - | ||||||
| 81 | */ | - | ||||||
| 82 | - | |||||||
| 83 | /*! \fn QStringBuilder::QStringBuilder(const A &a, const B &b) | - | ||||||
| 84 | Constructs a QStringBuilder from \a a and \a b. | - | ||||||
| 85 | */ | - | ||||||
| 86 | - | |||||||
| 87 | /* \fn QStringBuilder::operator%(const A &a, const B &b) | - | ||||||
| 88 | - | |||||||
| 89 | Returns a \c QStringBuilder object that is converted to a QString object | - | ||||||
| 90 | when assigned to a variable of QString type or passed to a function that | - | ||||||
| 91 | takes a QString parameter. | - | ||||||
| 92 | - | |||||||
| 93 | This function is usable with arguments of type \c QString, | - | ||||||
| 94 | \c QLatin1String, \c QStringRef, | - | ||||||
| 95 | \c QChar, \c QCharRef, \c QLatin1Char, and \c char. | - | ||||||
| 96 | */ | - | ||||||
| 97 | - | |||||||
| 98 | /* \fn QByteArray QStringBuilder::toLatin1() const | - | ||||||
| 99 | Returns a Latin-1 representation of the string as a QByteArray. The | - | ||||||
| 100 | returned byte array is undefined if the string contains non-Latin1 | - | ||||||
| 101 | characters. | - | ||||||
| 102 | */ | - | ||||||
| 103 | /* \fn QByteArray QStringBuilder::toUtf8() const | - | ||||||
| 104 | Returns a UTF-8 representation of the string as a QByteArray. | - | ||||||
| 105 | */ | - | ||||||
| 106 | - | |||||||
| 107 | - | |||||||
| 108 | /*! | - | ||||||
| 109 | \internal | - | ||||||
| 110 | */ | - | ||||||
| 111 | void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out) Q_DECL_NOTHROW | - | ||||||
| 112 | { | - | ||||||
| 113 | if (Q_UNLIKELY(len == -1)) {
| 8-274 | ||||||
| 114 | if (!a)
| 4 | ||||||
| 115 | return; executed 4 times by 2 tests: return;Executed by:
| 4 | ||||||
| 116 | len = int(strlen(a)); | - | ||||||
| 117 | } executed 4 times by 1 test: end of blockExecuted by:
| 4 | ||||||
| 118 | out = QUtf8::convertToUnicode(out, a, len); | - | ||||||
| 119 | } executed 278 times by 4 tests: end of blockExecuted by:
| 278 | ||||||
| 120 | - | |||||||
| 121 | QT_END_NAMESPACE | - | ||||||
| Source code | Switch to Preprocessed file |