Qt 4.8
qt-4.8.6
src
corelib
tools
qstringbuilder.cpp
Go to the documentation of this file.
1
/****************************************************************************
2
**
3
** Copyright (C) 2014 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
45
QT_BEGIN_NAMESPACE
46
143
/* \fn QStringBuilder::operator%(const A &a, const B &b)
144
145
Returns a \c QStringBuilder object that is converted to a QString object
146
when assigned to a variable of QString type or passed to a function that
147
takes a QString parameter.
148
149
This function is usable with arguments of type \c QString,
150
\c QLatin1String, \c QLatin1Literal, \c QStringRef,
151
\c QChar, \c QCharRef, \c QLatin1Char, and \c char.
152
*/
153
175
void
QAbstractConcatenable::convertFromAscii
(
const
char
*
a
,
int
len,
QChar
*&out)
176
{
177
#ifndef QT_NO_TEXTCODEC
178
if
(
QString::codecForCStrings
&& len) {
179
QString
tmp =
QString::fromAscii
(a, len > 0 ? len - 1 : -1);
180
memcpy(out, reinterpret_cast<const char *>(tmp.
constData
()),
sizeof
(
QChar
) * tmp.
size
());
181
out += tmp.
length
();
182
return
;
183
}
184
#endif
185
if
(len == -1) {
186
if
(!a)
187
return
;
188
while
(*a)
189
*out++ =
QLatin1Char
(*a++);
190
}
else
{
191
for
(
int
i = 0; i < len - 1; ++i)
192
*out++ =
QLatin1Char
(a[i]);
193
}
194
}
195
197
void
QAbstractConcatenable::convertToAscii
(
const
QChar
*
a
,
int
len,
char
*& out)
198
{
199
#ifndef QT_NO_TEXTCODEC
200
if
(
QString::codecForCStrings
) {
201
QByteArray
tmp =
QString::codecForCStrings
->
fromUnicode
(a, len);
202
memcpy(out, tmp.
constData
(), tmp.
size
());
203
out += tmp.
length
();
204
return
;
205
}
206
#endif
207
if
(len == -1) {
208
while
(a->
unicode
())
209
convertToLatin1
(*a++, out);
210
}
else
{
211
for
(
int
i = 0; i < len; ++i)
212
convertToLatin1
(a[i], out);
213
}
214
}
215
216
217
QT_END_NAMESPACE
QT_END_NAMESPACE
#define QT_END_NAMESPACE
This macro expands to.
Definition:
qglobal.h:90
QString::fromAscii
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition:
qstring.cpp:4276
QChar::unicode
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition:
qchar.h:251
QByteArray
The QByteArray class provides an array of bytes.
Definition:
qbytearray.h:135
QString::length
int length() const
Returns the number of characters in this string.
Definition:
qstring.h:696
a
long ASN1_INTEGER_get ASN1_INTEGER * a
Definition:
qsslsocket_openssl_symbols.cpp:104
QString
The QString class provides a Unicode character string.
Definition:
qstring.h:83
QAbstractConcatenable::convertToAscii
static void convertToAscii(const QChar *a, int len, char *&out)
Definition:
qstringbuilder.cpp:197
QAbstractConcatenable::convertFromAscii
static void convertFromAscii(const char *a, int len, QChar *&out)
Definition:
qstringbuilder.cpp:175
QChar
The QChar class provides a 16-bit Unicode character.
Definition:
qchar.h:72
QAbstractConcatenable::convertToLatin1
static void convertToLatin1(QChar a, char *&out)
Definition:
qstringbuilder.h:103
QT_BEGIN_NAMESPACE
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition:
qglobal.h:89
QTextCodec::fromUnicode
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
Definition:
qtextcodec.cpp:1388
QString::size
int size() const
Returns the number of characters in this string.
Definition:
qstring.h:102
QByteArray::length
int length() const
Same as size().
Definition:
qbytearray.h:356
QByteArray::constData
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition:
qbytearray.h:433
QString::codecForCStrings
static QTextCodec * codecForCStrings
Definition:
qstring.h:621
QByteArray::size
int size() const
Returns the number of bytes in this byte array.
Definition:
qbytearray.h:402
QLatin1Char
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition:
qchar.h:55
qstringbuilder.h
QString::constData
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition:
qstring.h:712
Qt 4.8 Source Code Browser