Merge remote-tracking branch 'origin/master' into api_changes
[profile/ivi/qtbase.git] / src / corelib / tools / qstringbuilder.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the QtCore module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
20 **
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
28 **
29 ** Other Usage
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qstringbuilder.h"
43 #include <QtCore/qtextcodec.h>
44
45 QT_BEGIN_NAMESPACE
46
47 /*!
48     \class QStringBuilder
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
104 /*! \internal
105  */
106 void QAbstractConcatenable::convertFromAscii(const char *a, int len, QChar *&out)
107 {
108     if (len == -1) {
109         if (!a)
110             return;
111         while (*a)
112             *out++ = QLatin1Char(*a++);
113     } else {
114         for (int i = 0; i < len; ++i)
115             *out++ = QLatin1Char(a[i]);
116     }
117 }
118
119 QT_END_NAMESPACE