summaryrefslogtreecommitdiffstats
path: root/src/corelib/tools
diff options
context:
space:
mode:
authorOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 17:21:55 (GMT)
committerOswald Buddenhagen <oswald.buddenhagen@nokia.com>2010-02-16 18:10:38 (GMT)
commite6b629f3ebc1d530218f01a735275e56bf474a18 (patch)
treefd1c40fbb935239d23886d5c688f46b61219e238 /src/corelib/tools
parent684e86adea5e89d6220560e82f1823f99920bb40 (diff)
downloadQt-e6b629f3ebc1d530218f01a735275e56bf474a18.zip
Qt-e6b629f3ebc1d530218f01a735275e56bf474a18.tar.gz
Qt-e6b629f3ebc1d530218f01a735275e56bf474a18.tar.bz2
add QString(const QChar *) c'tor
to complement the QString(const QChar *, int) one, which unfortunately clamps sizes below zero to zero instead of computing the length itself instead. Reviewed-by: denis Reviewed-by: joao
Diffstat (limited to 'src/corelib/tools')
-rw-r--r--src/corelib/tools/qstring.cpp36
-rw-r--r--src/corelib/tools/qstring.h3
2 files changed, 37 insertions, 2 deletions
diff --git a/src/corelib/tools/qstring.cpp b/src/corelib/tools/qstring.cpp
index dec59b7..f85d794 100644
--- a/src/corelib/tools/qstring.cpp
+++ b/src/corelib/tools/qstring.cpp
@@ -989,6 +989,40 @@ QString::QString(const QChar *unicode, int size)
}
}
+/*!
+ \since 4.7
+
+ Constructs a string initialized with the characters of the QChar array
+ \a unicode, which must be terminated with a 0.
+
+ QString makes a deep copy of the string data. The unicode data is copied as
+ is and the Byte Order Mark is preserved if present.
+*/
+QString::QString(const QChar *unicode)
+{
+ if (!unicode) {
+ d = &shared_null;
+ d->ref.ref();
+ } else {
+ int size = 0;
+ while (unicode[size] != 0)
+ ++size;
+ if (!size) {
+ d = &shared_empty;
+ d->ref.ref();
+ } else {
+ d = (Data*) qMalloc(sizeof(Data)+size*sizeof(QChar));
+ Q_CHECK_PTR(d);
+ d->ref = 1;
+ d->alloc = d->size = size;
+ d->clean = d->asciiCache = d->simpletext = d->righttoleft = d->capacity = 0;
+ d->data = d->array;
+ memcpy(d->array, unicode, size * sizeof(QChar));
+ d->array[size] = '\0';
+ }
+ }
+}
+
/*!
Constructs a string of the given \a size with every character set
@@ -3867,7 +3901,7 @@ QString QString::fromUtf8(const char *str, int size)
host byte order is assumed.
This function is comparatively slow.
- Use QString(const ushort *, int) if possible.
+ Use QString(const ushort *, int) or QString(const ushort *) if possible.
QString makes a deep copy of the Unicode data.
diff --git a/src/corelib/tools/qstring.h b/src/corelib/tools/qstring.h
index 702a21a..8de3c7d 100644
--- a/src/corelib/tools/qstring.h
+++ b/src/corelib/tools/qstring.h
@@ -91,7 +91,8 @@ class Q_CORE_EXPORT QString
{
public:
inline QString();
- QString(const QChar *unicode, int size);
+ QString(const QChar *unicode, int size); // Qt5: don't cap size < 0
+ explicit QString(const QChar *unicode); // Qt5: merge with the above
QString(QChar c);
QString(int size, QChar c);
inline QString(const QLatin1String &latin1);