summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--doc/src/snippets/code/src_corelib_tools_qbytearray.cpp17
-rw-r--r--src/corelib/io/qurl.cpp134
-rw-r--r--src/corelib/tools/qbytearray.cpp18
-rw-r--r--src/gui/text/qfontengine_s60.cpp36
-rw-r--r--src/gui/text/qfontengine_s60_p.h3
5 files changed, 158 insertions, 50 deletions
diff --git a/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp b/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
index e48ca8c..8bb2566 100644
--- a/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
+++ b/doc/src/snippets/code/src_corelib_tools_qbytearray.cpp
@@ -401,5 +401,22 @@ QByteArray text = QByteArray::fromHex("517420697320677265617421");
text.data(); // returns "Qt is great!"
//! [45]
+//! [46]
+QString tmp = "test";
+QByteArray text = tmp.toLocal8Bit();
+char *data = new char[text.size()]
+strcpy(data, text.data());
+delete [] data;
+//! [46]
+
+//! [47]
+QString tmp = "test";
+QByteArray text = tmp.toLocal8Bit();
+char *data = new char[text.size() + 1]
+strcpy(data, text.data());
+delete [] data;
+//! [47]
+
}
+
diff --git a/src/corelib/io/qurl.cpp b/src/corelib/io/qurl.cpp
index 1ae2384..88ba4e5 100644
--- a/src/corelib/io/qurl.cpp
+++ b/src/corelib/io/qurl.cpp
@@ -4074,7 +4074,7 @@ QString QUrlPrivate::createErrorString()
\sa setUrl(), setEncodedUrl(), fromEncoded(), TolerantMode
*/
-QUrl::QUrl(const QString &url) : d(new QUrlPrivate)
+QUrl::QUrl(const QString &url) : d(0)
{
if (!url.isEmpty())
setUrl(url);
@@ -4087,18 +4087,20 @@ QUrl::QUrl(const QString &url) : d(new QUrlPrivate)
\sa setUrl()
*/
-QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(new QUrlPrivate)
+QUrl::QUrl(const QString &url, ParsingMode parsingMode) : d(0)
{
if (!url.isEmpty())
setUrl(url, parsingMode);
- else
+ else {
+ d = new QUrlPrivate;
d->parsingMode = parsingMode;
+ }
}
/*!
Constructs an empty QUrl object.
*/
-QUrl::QUrl() : d(new QUrlPrivate)
+QUrl::QUrl() : d(0)
{
}
@@ -4107,7 +4109,8 @@ QUrl::QUrl() : d(new QUrlPrivate)
*/
QUrl::QUrl(const QUrl &other) : d(other.d)
{
- d->ref.ref();
+ if (d)
+ d->ref.ref();
}
/*!
@@ -4115,7 +4118,7 @@ QUrl::QUrl(const QUrl &other) : d(other.d)
*/
QUrl::~QUrl()
{
- if (!d->ref.deref())
+ if (d && !d->ref.deref())
delete d;
}
@@ -4130,6 +4133,8 @@ QUrl::~QUrl()
*/
bool QUrl::isValid() const
{
+ if (!d) return false;
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate();
@@ -4141,6 +4146,8 @@ bool QUrl::isValid() const
*/
bool QUrl::isEmpty() const
{
+ if (!d) return true;
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed))
return d->encodedOriginal.isEmpty();
else
@@ -4161,8 +4168,9 @@ bool QUrl::isEmpty() const
*/
void QUrl::clear()
{
- detach();
- d->clear();
+ if (d && !d->ref.deref())
+ delete d;
+ d = 0;
}
/*!
@@ -4261,8 +4269,9 @@ static inline char toHex(quint8 c)
*/
void QUrl::setEncodedUrl(const QByteArray &encodedUrl, ParsingMode parsingMode)
{
- clear();
QByteArray tmp = encodedUrl;
+ if (!d) d = new QUrlPrivate;
+ else d->clear();
if ((d->parsingMode = parsingMode) == TolerantMode) {
// Replace stray % with %25
QByteArray copy = tmp;
@@ -4336,6 +4345,7 @@ void QUrl::setEncodedUrl(const QByteArray &encodedUrl, ParsingMode parsingMode)
*/
void QUrl::setScheme(const QString &scheme)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4351,6 +4361,7 @@ void QUrl::setScheme(const QString &scheme)
*/
QString QUrl::scheme() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->scheme;
@@ -4374,6 +4385,8 @@ QString QUrl::scheme() const
*/
void QUrl::setAuthority(const QString &authority)
{
+ if (!d) d = new QUrlPrivate;
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4389,6 +4402,8 @@ void QUrl::setAuthority(const QString &authority)
*/
QString QUrl::authority() const
{
+ if (!d) return QString();
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->authority();
@@ -4409,6 +4424,8 @@ QString QUrl::authority() const
*/
void QUrl::setUserInfo(const QString &userInfo)
{
+ if (!d) d = new QUrlPrivate;
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4422,6 +4439,8 @@ void QUrl::setUserInfo(const QString &userInfo)
*/
QString QUrl::userInfo() const
{
+ if (!d) return QString();
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->userInfo();
@@ -4436,6 +4455,8 @@ QString QUrl::userInfo() const
*/
void QUrl::setUserName(const QString &userName)
{
+ if (!d) d = new QUrlPrivate;
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4452,6 +4473,8 @@ void QUrl::setUserName(const QString &userName)
*/
QString QUrl::userName() const
{
+ if (!d) return QString();
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->userInfo(); // causes the unencoded form to be set
@@ -4473,6 +4496,7 @@ QString QUrl::userName() const
*/
void QUrl::setEncodedUserName(const QByteArray &userName)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4493,6 +4517,7 @@ void QUrl::setEncodedUserName(const QByteArray &userName)
*/
QByteArray QUrl::encodedUserName() const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->ensureEncodedParts();
@@ -4508,6 +4533,7 @@ QByteArray QUrl::encodedUserName() const
*/
void QUrl::setPassword(const QString &password)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4524,6 +4550,7 @@ void QUrl::setPassword(const QString &password)
*/
QString QUrl::password() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->userInfo(); // causes the unencoded form to be set
@@ -4545,6 +4572,7 @@ QString QUrl::password() const
*/
void QUrl::setEncodedPassword(const QByteArray &password)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4565,6 +4593,7 @@ void QUrl::setEncodedPassword(const QByteArray &password)
*/
QByteArray QUrl::encodedPassword() const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->ensureEncodedParts();
@@ -4579,6 +4608,7 @@ QByteArray QUrl::encodedPassword() const
*/
void QUrl::setHost(const QString &host)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized | QUrlPrivate::HostCanonicalized);
@@ -4592,6 +4622,7 @@ void QUrl::setHost(const QString &host)
*/
QString QUrl::host() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (d->host.isEmpty() || d->host.at(0) != QLatin1Char('['))
@@ -4645,6 +4676,7 @@ QByteArray QUrl::encodedHost() const
*/
void QUrl::setPort(int port)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4662,6 +4694,7 @@ void QUrl::setPort(int port)
*/
int QUrl::port() const
{
+ if (!d) return -1;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Validated)) d->validate();
return d->port;
@@ -4680,6 +4713,7 @@ int QUrl::port() const
*/
int QUrl::port(int defaultPort) const
{
+ if (!d) return defaultPort;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->port == -1 ? defaultPort : d->port;
}
@@ -4699,6 +4733,7 @@ int QUrl::port(int defaultPort) const
*/
void QUrl::setPath(const QString &path)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4714,6 +4749,7 @@ void QUrl::setPath(const QString &path)
*/
QString QUrl::path() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (d->path.isNull()) {
@@ -4745,6 +4781,7 @@ QString QUrl::path() const
*/
void QUrl::setEncodedPath(const QByteArray &path)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4765,6 +4802,7 @@ void QUrl::setEncodedPath(const QByteArray &path)
*/
QByteArray QUrl::encodedPath() const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->ensureEncodedParts();
@@ -4780,6 +4818,7 @@ QByteArray QUrl::encodedPath() const
*/
bool QUrl::hasQuery() const
{
+ if (!d) return false;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->hasQuery;
@@ -4809,6 +4848,7 @@ bool QUrl::hasQuery() const
*/
void QUrl::setQueryDelimiters(char valueDelimiter, char pairDelimiter)
{
+ if (!d) d = new QUrlPrivate;
detach();
d->valueDelimiter = valueDelimiter;
@@ -4821,6 +4861,7 @@ void QUrl::setQueryDelimiters(char valueDelimiter, char pairDelimiter)
*/
char QUrl::queryPairDelimiter() const
{
+ if (!d) return '&';
return d->pairDelimiter;
}
@@ -4830,6 +4871,7 @@ char QUrl::queryPairDelimiter() const
*/
char QUrl::queryValueDelimiter() const
{
+ if (!d) return '=';
return d->valueDelimiter;
}
@@ -4852,6 +4894,7 @@ char QUrl::queryValueDelimiter() const
*/
void QUrl::setEncodedQuery(const QByteArray &query)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -4871,6 +4914,7 @@ void QUrl::setEncodedQuery(const QByteArray &query)
*/
void QUrl::setQueryItems(const QList<QPair<QString, QString> > &query)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -4910,6 +4954,7 @@ void QUrl::setQueryItems(const QList<QPair<QString, QString> > &query)
*/
void QUrl::setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &query)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -4939,6 +4984,7 @@ void QUrl::setEncodedQueryItems(const QList<QPair<QByteArray, QByteArray> > &que
*/
void QUrl::addQueryItem(const QString &key, const QString &value)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -4973,6 +5019,7 @@ void QUrl::addQueryItem(const QString &key, const QString &value)
*/
void QUrl::addEncodedQueryItem(const QByteArray &key, const QByteArray &value)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -4993,6 +5040,7 @@ void QUrl::addEncodedQueryItem(const QByteArray &key, const QByteArray &value)
*/
QList<QPair<QString, QString> > QUrl::queryItems() const
{
+ if (!d) return QList<QPair<QString, QString> >();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QList<QPair<QString, QString> > itemMap;
@@ -5025,6 +5073,7 @@ QList<QPair<QString, QString> > QUrl::queryItems() const
*/
QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const
{
+ if (!d) return QList<QPair<QByteArray, QByteArray> >();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QList<QPair<QByteArray, QByteArray> > itemMap;
@@ -5053,6 +5102,7 @@ QList<QPair<QByteArray, QByteArray> > QUrl::encodedQueryItems() const
*/
bool QUrl::hasQueryItem(const QString &key) const
{
+ if (!d) return false;
return hasEncodedQueryItem(toPercentEncoding(key, queryExcludeChars));
}
@@ -5071,6 +5121,7 @@ bool QUrl::hasQueryItem(const QString &key) const
*/
bool QUrl::hasEncodedQueryItem(const QByteArray &key) const
{
+ if (!d) return false;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
int pos = 0;
@@ -5093,6 +5144,7 @@ bool QUrl::hasEncodedQueryItem(const QByteArray &key) const
*/
QString QUrl::queryItemValue(const QString &key) const
{
+ if (!d) return QString();
QByteArray tmp = encodedQueryItemValue(toPercentEncoding(key, queryExcludeChars));
return fromPercentEncodingMutable(&tmp);
}
@@ -5112,6 +5164,7 @@ QString QUrl::queryItemValue(const QString &key) const
*/
QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
int pos = 0;
@@ -5135,6 +5188,7 @@ QByteArray QUrl::encodedQueryItemValue(const QByteArray &key) const
*/
QStringList QUrl::allQueryItemValues(const QString &key) const
{
+ if (!d) return QStringList();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QByteArray encodedKey = toPercentEncoding(key, queryExcludeChars);
@@ -5172,6 +5226,7 @@ QStringList QUrl::allQueryItemValues(const QString &key) const
*/
QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const
{
+ if (!d) return QList<QByteArray>();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QList<QByteArray> values;
@@ -5199,6 +5254,7 @@ QList<QByteArray> QUrl::allEncodedQueryItemValues(const QByteArray &key) const
*/
void QUrl::removeQueryItem(const QString &key)
{
+ if (!d) return;
removeEncodedQueryItem(toPercentEncoding(key, queryExcludeChars));
}
@@ -5217,6 +5273,7 @@ void QUrl::removeQueryItem(const QString &key)
*/
void QUrl::removeEncodedQueryItem(const QByteArray &key)
{
+ if (!d) return;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -5243,6 +5300,7 @@ void QUrl::removeEncodedQueryItem(const QByteArray &key)
*/
void QUrl::removeAllQueryItems(const QString &key)
{
+ if (!d) return;
removeAllEncodedQueryItems(toPercentEncoding(key, queryExcludeChars));
}
@@ -5261,6 +5319,7 @@ void QUrl::removeAllQueryItems(const QString &key)
*/
void QUrl::removeAllEncodedQueryItems(const QByteArray &key)
{
+ if (!d) return;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
@@ -5284,6 +5343,7 @@ void QUrl::removeAllEncodedQueryItems(const QByteArray &key)
*/
QByteArray QUrl::encodedQuery() const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->query;
@@ -5308,6 +5368,7 @@ QByteArray QUrl::encodedQuery() const
*/
void QUrl::setFragment(const QString &fragment)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -5324,6 +5385,7 @@ void QUrl::setFragment(const QString &fragment)
*/
QString QUrl::fragment() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (d->fragment.isNull() && !d->encodedFragment.isNull()) {
@@ -5354,6 +5416,7 @@ QString QUrl::fragment() const
*/
void QUrl::setEncodedFragment(const QByteArray &fragment)
{
+ if (!d) d = new QUrlPrivate;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
detach();
QURL_UNSETFLAG(d->stateFlags, QUrlPrivate::Validated | QUrlPrivate::Normalized);
@@ -5375,6 +5438,7 @@ void QUrl::setEncodedFragment(const QByteArray &fragment)
*/
QByteArray QUrl::encodedFragment() const
{
+ if (!d) return QByteArray();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
d->ensureEncodedParts();
@@ -5390,6 +5454,7 @@ QByteArray QUrl::encodedFragment() const
*/
bool QUrl::hasFragment() const
{
+ if (!d) return false;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->hasFragment;
@@ -5416,6 +5481,8 @@ bool QUrl::hasFragment() const
*/
QUrl QUrl::resolved(const QUrl &relative) const
{
+ if (!d) return relative;
+ if (!relative.d) return *this;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (!QURL_HASFLAG(relative.d->stateFlags, QUrlPrivate::Parsed))
@@ -5432,6 +5499,7 @@ QUrl QUrl::resolved(const QUrl &relative) const
if (!relative.authority().isEmpty()) {
t = relative;
} else {
+ t.d = new QUrlPrivate;
if (relative.d->encodedPath.isEmpty()) {
t.d->encodedPath = d->encodedPath;
t.setEncodedQuery(relative.d->hasQuery ? relative.d->query : d->query);
@@ -5462,6 +5530,7 @@ QUrl QUrl::resolved(const QUrl &relative) const
*/
bool QUrl::isRelative() const
{
+ if (!d) return true;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
return d->scheme.isEmpty();
@@ -5476,6 +5545,7 @@ bool QUrl::isRelative() const
*/
QString QUrl::toString(FormattingOptions options) const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QString url;
@@ -5527,6 +5597,7 @@ QString QUrl::toString(FormattingOptions options) const
*/
QByteArray QUrl::toEncoded(FormattingOptions options) const
{
+ if (!d) return QByteArray();
return d->toEncoded(options);
}
@@ -5777,7 +5848,9 @@ void QUrl::setIdnWhitelist(const QStringList &list)
*/
bool QUrl::operator <(const QUrl &url) const
{
+ if (!d) return url.d ? QByteArray() < url.d->normalized() : false;
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
+ if (!url.d) return d->normalized() < QByteArray();
if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
return d->normalized() < url.d->normalized();
}
@@ -5788,6 +5861,8 @@ bool QUrl::operator <(const QUrl &url) const
*/
bool QUrl::operator ==(const QUrl &url) const
{
+ if (!d) return url.isEmpty();
+ if (!url.d) return isEmpty();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
if (!QURL_HASFLAG(url.d->stateFlags, QUrlPrivate::Parsed)) url.d->parse();
return d->normalized() == url.d->normalized();
@@ -5807,7 +5882,17 @@ bool QUrl::operator !=(const QUrl &url) const
*/
QUrl &QUrl::operator =(const QUrl &url)
{
- qAtomicAssign(d, url.d);
+ if (!d) {
+ if (url.d) {
+ url.d->ref.ref();
+ d = url.d;
+ }
+ } else {
+ if (url.d)
+ qAtomicAssign(d, url.d);
+ else
+ clear();
+ }
return *this;
}
@@ -5816,8 +5901,13 @@ QUrl &QUrl::operator =(const QUrl &url)
*/
QUrl &QUrl::operator =(const QString &url)
{
- QUrl tmp(url);
- qAtomicAssign(d, tmp.d);
+ if (url.isEmpty()) {
+ clear();
+ } else {
+ QUrl tmp(url);
+ if (!d) d = new QUrlPrivate;
+ qAtomicAssign(d, tmp.d);
+ }
return *this;
}
@@ -5826,14 +5916,19 @@ QUrl &QUrl::operator =(const QString &url)
Forces a detach.
*/
void QUrl::detach()
-{ qAtomicDetach(d); }
+{
+ if (!d)
+ d = new QUrlPrivate;
+ else
+ qAtomicDetach(d);
+}
/*!
\internal
*/
bool QUrl::isDetached() const
{
- return d->ref == 1;
+ return !d || d->ref == 1;
}
@@ -5875,6 +5970,7 @@ QUrl QUrl::fromLocalFile(const QString &localFile)
*/
QString QUrl::toLocalFile() const
{
+ if (!d) return QString();
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
QString tmp;
@@ -5903,9 +5999,15 @@ QString QUrl::toLocalFile() const
*/
bool QUrl::isParentOf(const QUrl &childUrl) const
{
+ QString childPath = childUrl.path();
+
+ if (!d)
+ return ((childUrl.scheme().isEmpty())
+ && (childUrl.authority().isEmpty())
+ && childPath.length() > 0 && childPath.at(0) == QLatin1Char('/'));
+
if (!QURL_HASFLAG(d->stateFlags, QUrlPrivate::Parsed)) d->parse();
- QString childPath = childUrl.path();
QString ourPath = path();
return ((childUrl.scheme().isEmpty() || d->scheme == childUrl.scheme())
@@ -6145,6 +6247,8 @@ QDebug operator<<(QDebug d, const QUrl &url)
*/
QString QUrl::errorString() const
{
+ if (!d)
+ return QLatin1String(QT_TRANSLATE_NOOP(QUrl, "Invalid URL \"\": ")); // XXX not a good message, but the one an empty URL produces
return d->createErrorString();
}
diff --git a/src/corelib/tools/qbytearray.cpp b/src/corelib/tools/qbytearray.cpp
index 6f29057..2ab2b05 100644
--- a/src/corelib/tools/qbytearray.cpp
+++ b/src/corelib/tools/qbytearray.cpp
@@ -903,8 +903,8 @@ QByteArray &QByteArray::operator=(const char *str)
The last byte in the byte array is at position size() - 1. In
addition, QByteArray ensures that the byte at position size() is
always '\\0', so that you can use the return value of data() and
- constData() as arguments to functions that expect
- '\\0'-terminated strings.
+ constData() as arguments to functions that expect '\\0'-terminated
+ strings.
Example:
\snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 6
@@ -997,7 +997,9 @@ QByteArray &QByteArray::operator=(const char *str)
Returns a pointer to the data stored in the byte array. The
pointer can be used to access and modify the bytes that compose
- the array. The data is '\\0'-terminated.
+ the array. The data is '\\0'-terminated, i.e. the number of
+ bytes in the returned character string is size() + 1 for the
+ '\\0' terminator.
Example:
\snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 8
@@ -1009,6 +1011,16 @@ QByteArray &QByteArray::operator=(const char *str)
This function is mostly useful to pass a byte array to a function
that accepts a \c{const char *}.
+ The following example makes a copy of the char* returned by
+ data(), but it will corrupt the heap and cause a crash because it
+ does not allocate a byte for the '\\0' at the end:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 46
+
+ This one allocates the correct amount of space:
+
+ \snippet doc/src/snippets/code/src_corelib_tools_qbytearray.cpp 47
+
Note: A QByteArray can store any byte values including '\\0's,
but most functions that take \c{char *} arguments assume that the
data ends at the first '\\0' they encounter.
diff --git a/src/gui/text/qfontengine_s60.cpp b/src/gui/text/qfontengine_s60.cpp
index 1f9b857..0012f6e 100644
--- a/src/gui/text/qfontengine_s60.cpp
+++ b/src/gui/text/qfontengine_s60.cpp
@@ -45,12 +45,11 @@
#include <private/qapplication_p.h>
#include "qimage.h"
#include "qt_s60_p.h"
-#include "qpixmap_s60_p.h"
#include <e32base.h>
#include <e32std.h>
-#include <EIKENV.H>
-#include <GDI.H>
+#include <eikenv.h>
+#include <gdi.h>
QT_BEGIN_NAMESPACE
@@ -135,42 +134,21 @@ QFontEngineS60::QFontEngineS60(const QFontDef &request, const QFontEngineS60Exte
{
QFontEngine::fontDef = request;
m_fontSizeInPixels = (request.pixelSize >= 0)?
- request.pixelSize:pointsToPixels(request.pointSize);
-
- QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
-
- m_textRenderBitmap = q_check_ptr(new CFbsBitmap()); // CBase derived object needs check on new
- const TSize bitmapSize(1, 1); // It is just a dummy bitmap that I need to keep the font alive (or maybe not)
- qt_symbian_throwIfError(m_textRenderBitmap->Create(bitmapSize, EGray256));
- QT_TRAP_THROWING(m_textRenderBitmapDevice = CFbsBitmapDevice::NewL(m_textRenderBitmap));
- qt_symbian_throwIfError(m_textRenderBitmapDevice->CreateContext(m_textRenderBitmapGc));
- cache_cost = sizeof(QFontEngineS60) + bitmapSize.iHeight * bitmapSize.iWidth * 4;
+ request.pixelSize:pointsToPixels(request.pointSize);
TFontSpec fontSpec(qt_QString2TPtrC(request.family), m_fontSizeInPixels);
fontSpec.iFontStyle.SetBitmapType(EAntiAliasedGlyphBitmap);
fontSpec.iFontStyle.SetPosture(request.style == QFont::StyleNormal?EPostureUpright:EPostureItalic);
fontSpec.iFontStyle.SetStrokeWeight(request.weight > QFont::Normal?EStrokeWeightBold:EStrokeWeightNormal);
- const TInt errorCode = m_textRenderBitmapDevice->GetNearestFontInPixels(m_font, fontSpec);
+ const TInt errorCode = S60->screenDevice()->GetNearestFontToDesignHeightInPixels(m_font, fontSpec);
Q_ASSERT(errorCode == 0);
- m_textRenderBitmapGc->UseFont(m_font);
-
- lock.relock();
+
+ cache_cost = sizeof(QFontEngineS60);
}
QFontEngineS60::~QFontEngineS60()
{
- QSymbianFbsHeapLock lock(QSymbianFbsHeapLock::Unlock);
-
- m_textRenderBitmapGc->DiscardFont();
- delete m_textRenderBitmapGc;
- m_textRenderBitmapGc = NULL;
- m_textRenderBitmapDevice->ReleaseFont(m_font);
- delete m_textRenderBitmapDevice;
- m_textRenderBitmapDevice = NULL;
- delete m_textRenderBitmap;
- m_textRenderBitmap = NULL;
-
- lock.relock();
+ S60->screenDevice()->ReleaseFont(m_font);
}
bool QFontEngineS60::stringToCMap(const QChar *characters, int len, QGlyphLayout *glyphs, int *nglyphs, QTextEngine::ShaperFlags flags) const
diff --git a/src/gui/text/qfontengine_s60_p.h b/src/gui/text/qfontengine_s60_p.h
index f9d28b4..5f777be 100644
--- a/src/gui/text/qfontengine_s60_p.h
+++ b/src/gui/text/qfontengine_s60_p.h
@@ -126,9 +126,6 @@ private:
QFixed glyphAdvance(HB_Glyph glyph) const;
- CFbsBitmap *m_textRenderBitmap;
- CFbsBitmapDevice *m_textRenderBitmapDevice;
- CFbsBitGc *m_textRenderBitmapGc;
CFont* m_font;
const QFontEngineS60Extensions *m_extensions;
qreal m_fontSizeInPixels;