Qt 4.8
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 
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
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 
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
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
ushort unicode() const
This is an overloaded member function, provided for convenience. It differs from the above function o...
Definition: qchar.h:251
The QByteArray class provides an array of bytes.
Definition: qbytearray.h:135
int length() const
Returns the number of characters in this string.
Definition: qstring.h:696
long ASN1_INTEGER_get ASN1_INTEGER * a
The QString class provides a Unicode character string.
Definition: qstring.h:83
static void convertToAscii(const QChar *a, int len, char *&out)
static void convertFromAscii(const char *a, int len, QChar *&out)
The QChar class provides a 16-bit Unicode character.
Definition: qchar.h:72
static void convertToLatin1(QChar a, char *&out)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QByteArray fromUnicode(const QString &uc) const
Converts str from Unicode to the encoding of this codec, and returns the result in a QByteArray...
int size() const
Returns the number of characters in this string.
Definition: qstring.h:102
int length() const
Same as size().
Definition: qbytearray.h:356
const char * constData() const
Returns a pointer to the data stored in the byte array.
Definition: qbytearray.h:433
static QTextCodec * codecForCStrings
Definition: qstring.h:621
int size() const
Returns the number of bytes in this byte array.
Definition: qbytearray.h:402
The QLatin1Char class provides an 8-bit ASCII/Latin-1 character.
Definition: qchar.h:55
const QChar * constData() const
Returns a pointer to the data stored in the QString.
Definition: qstring.h:712