[SCM] WebKit Debian packaging branch, debian/unstable, updated. debian/1.1.15-1-40151-g37bb677
gramps
gramps at 268f45cc-cd09-0410-ab3c-d52691b4dbfc
Sat Sep 26 05:47:51 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit a725b67122b64771bb1f2fe95c5a8f6ee9ab0c60
Author: gramps <gramps at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Fri Sep 28 18:20:50 2001 +0000
More QString implementation
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@220 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/kwq/KWQString.h b/WebCore/kwq/KWQString.h
index 62310e0..7ffa64e 100644
--- a/WebCore/kwq/KWQString.h
+++ b/WebCore/kwq/KWQString.h
@@ -202,7 +202,6 @@ public:
void truncate(uint pos);
void fill(QChar, int len=-1);
- QString arg (int &);
QString arg(int a, int fieldwidth=0, int base=10) const;
QString arg(const QString &, int fieldwidth=0) const;
@@ -242,6 +241,11 @@ public:
// NOTE: this is NOT private:
CFMutableStringRef s;
+ mutable void *cache;
+ enum CacheType {
+ CacheInvalid, CacheUnicode, CacheLatin1
+ };
+ mutable CacheType cacheType;
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
diff --git a/WebCore/kwq/KWQString.mm b/WebCore/kwq/KWQString.mm
index 29224fc..70221cb 100644
--- a/WebCore/kwq/KWQString.mm
+++ b/WebCore/kwq/KWQString.mm
@@ -25,87 +25,126 @@
// FIXME: obviously many functions here can be made inline
+// #include <Foundation/Foundation.h>
#include <qstring.h>
#ifndef USING_BORROWED_QSTRING
+// QString class ===============================================================
+
+// constants -------------------------------------------------------------------
+
const QString QString::null;
-// constructors, copy constructors, and destructors ------------------------
+// constructors, copy constructors, and destructors ----------------------------
QString::QString()
{
s = NULL;
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(QChar qc)
{
s = CFStringCreateMutable(NULL, 0);
- CFStringAppendCharacters(s, &qc.c, 1);
+ if (s) {
+ CFStringAppendCharacters(s, &qc.c, 1);
+ }
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QByteArray &qba)
{
if (qba.size() && *qba.data()) {
s = CFStringCreateMutable(NULL, 0);
- const int capacity = 64;
- UniChar buf[capacity];
- int fill = 0;
- for (uint len = 0; (len < qba.size()) && qba[len]; len++) {
- buf[fill] = qba[len];
- fill++;
- if (fill == capacity) {
+ if (s) {
+ const int capacity = 64;
+ UniChar buf[capacity];
+ int fill = 0;
+ for (uint len = 0; (len < qba.size()) && qba[len]; len++) {
+ buf[fill] = qba[len];
+ fill++;
+ if (fill == capacity) {
+ CFStringAppendCharacters(s, buf, fill);
+ fill = 0;
+ }
+ }
+ if (fill) {
CFStringAppendCharacters(s, buf, fill);
- fill = 0;
}
}
- if (fill) {
- CFStringAppendCharacters(s, buf, fill);
- }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QChar *qcs, uint len)
{
if (qcs || len) {
s = CFStringCreateMutable(NULL, 0);
- CFStringAppendCharacters(s, &qcs->c, len);
+ if (s) {
+ CFStringAppendCharacters(s, &qcs->c, len);
+ }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const char *chs)
{
if (chs && *chs) {
s = CFStringCreateMutable(NULL, 0);
- // FIXME: is ISO Latin-1 the correct encoding?
- CFStringAppendCString(s, chs, kCFStringEncodingISOLatin1);
+ if (s) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ CFStringAppendCString(s, chs, kCFStringEncodingISOLatin1);
+ }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QString &other)
{
+ // shared copy
+ if (other.s) {
+ CFRetain(other.s);
+ }
s = other.s;
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::~QString()
{
- CFRelease(s);
+ if (s) {
+ CFRelease(s);
+ }
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ }
}
-// assignment operators ----------------------------------------------------
+// assignment operators --------------------------------------------------------
QString &QString::operator=(const QString &qs)
{
// shared copy
- CFRetain(qs.s);
- CFRelease(s);
+ if (qs.s) {
+ CFRetain(qs.s);
+ }
+ if (s) {
+ CFRelease(s);
+ }
s = qs.s;
+ cacheType = CacheInvalid;
return *this;
}
@@ -129,276 +168,327 @@ QString &QString::operator=(char ch)
return *this = QString(QChar(ch));
}
-// member functions --------------------------------------------------------
+// member functions ------------------------------------------------------------
-bool QString::isNull() const
+uint QString::length() const
{
- return (s == NULL);
+ return s ? CFStringGetLength(s) : 0;
}
-bool QString::isEmpty() const
+const QChar *QString::unicode() const
{
- return (s == NULL || CFStringGetLength(s) == 0);
+ UniChar *ucs = NULL;
+ uint len = length();
+ if (len) {
+ ucs = const_cast<UniChar *>(CFStringGetCharactersPtr(s));
+ if (!ucs) {
+ // NSLog(@"CFStringGetCharactersPtr returned NULL!!!");
+ if (cacheType != CacheUnicode) {
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ cache = NULL;
+ cacheType = CacheInvalid;
+ }
+ if (!cache) {
+ cache = CFAllocatorAllocate(CFAllocatorGetDefault(),
+ len * sizeof (UniChar), 0);
+ }
+ if (cache) {
+ CFStringGetCharacters(s, CFRangeMake(0, len), cache);
+ cacheType = CacheUnicode;
+ }
+ }
+ ucs = cache;
+ }
+ }
+ // NOTE: this only works since our QChar implementation contains a single
+ // UniChar data member
+ return reinterpret_cast<const QChar *>(ucs);
}
-uint QString::length() const
+const char *QString::latin1() const
{
- return CFStringGetLength(s);
+ char *chs = NULL;
+ uint len = length();
+ if (len) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ chs = const_cast<char *>(CFStringGetCStringPtr(s,
+ kCFStringEncodingISOLatin1));
+ if (!chs) {
+ // NSLog(@"CFStringGetCStringPtr returned NULL!!!");
+ if (cacheType != CacheLatin1) {
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ cache = NULL;
+ cacheType = CacheInvalid;
+ }
+ if (!cache) {
+ cache = CFAllocatorAllocate(CFAllocatorGetDefault(),
+ len + 1, 0);
+ }
+ if (cache) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ if (!CFStringGetCString(s, cache, len + 1,
+ kCFStringEncodingISOLatin1)) {
+ // NSLog(@"CFStringGetCString returned FALSE!!!");
+ *reinterpret_cast<char *>(cache) = '\0';
+ }
+ cacheType = CacheLatin1;
+ }
+ }
+ chs = cache;
+ }
+ }
+ if (!chs) {
+ static char emptyString[] = "";
+ chs = emptyString;
+ }
+ return chs;
}
-bool QString::startsWith(const QString &s) const
+const char *QString::ascii() const
{
- // FIXME: awaiting real implementation
+ return latin1();
+}
+
+bool QString::isNull() const
+{
+ // NOTE: do NOT use "unicode() == NULL"
+ return s == NULL;
+}
+
+bool QString::isEmpty() const
+{
+ return length() == 0;
+}
+
+bool QString::startsWith(const QString &) const
+{
+ // FIXME: not yet implemented
return FALSE;
}
int QString::toInt() const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::toInt(bool *b, int base=10) const
+int QString::toInt(bool *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-uint QString::toUInt(bool *ok=0, int base=10) const
+uint QString::toUInt(bool *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-long QString::toLong(bool *ok=0, int base=10) const
+long QString::toLong(bool *, int) const
{
- // FIXME: awaiting real implementation
- return 0L;
+ // FIXME: not yet implemented
+ return 0;
}
-float QString::toFloat(bool *b=0) const
+float QString::toFloat(bool *) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0.0f;
}
-QString &QString::prepend(const QString &s)
+QString &QString::prepend(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::append(const char *s)
+QString &QString::append(const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::append(const QString &s)
+QString &QString::append(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-int QString::contains(const char *c, bool cs=TRUE) const
+int QString::contains(const char *, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::contains(char c) const
+int QString::contains(char) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(char c, int index=0) const
+int QString::find(char, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const char *s, int index=0, bool b=0) const
+int QString::find(const char *, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const QString &s, int index=0, bool b=0) const
+int QString::find(const QString &, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const QRegExp &r, int index=0, bool b=0) const
+int QString::find(const QRegExp &, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::findRev(char c, int index=0) const
+int QString::findRev(char, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::findRev(const char *s, int index=0) const
+int QString::findRev(const char *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-QString &QString::remove(uint u1, uint u2)
+QString &QString::remove(uint, uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString &QString::replace(const QRegExp &, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::insert(uint i, char c)
+QString &QString::insert(uint, char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-void QString::truncate(uint pos)
+void QString::truncate(uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-void QString::fill(QChar c, int len=-1)
+void QString::fill(QChar, int)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-QString QString::arg(int &a)
+QString QString::arg(int, int, int) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::arg(int a, int fieldwidth=0, int base=10) const
+QString QString::arg(const QString &, int) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::arg(const QString &s, int fieldwidth=0) const
+QString QString::left(uint) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::left(uint pos) const
+QString QString::right(uint) const
{
- // FIXME: awaiting real implementation
- return *this;
-}
-
-QString QString::right(uint pos) const
-{
- // FIXME: awaiting real implementation
- return *this;
-}
-
-QString QString::mid(int pos, int len=0xffffffff) const
-{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::fromLatin1(const char *s, int len=-1)
+QString QString::mid(int, int) const
{
- // FIXME: awaiting real implementation
- return NULL;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-const char *QString::latin1() const
+QString QString::fromLatin1(const char *, int)
{
- // FIXME: awaiting real implementation
- return (const char *)CFStringGetCStringPtr(s, kCFStringEncodingISOLatin1);
-}
-
-const char *QString::ascii() const
-{
- // FIXME: awaiting real implementation
- return NULL;
-}
-
-const QChar *QString::unicode() const
-{
- // FIXME: awaiting real implementation
- return (QChar *)CFStringGetCharactersPtr(s);
+ // FIXME: not yet implemented
+ return QString();
}
QCString QString::utf8() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QCString();
}
QCString QString::local8Bit() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QCString();
}
-QString &QString::setUnicode(const QChar *s, uint i)
+QString &QString::setUnicode(const QChar *, uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::setNum(int i, int base=10)
+QString &QString::setNum(int, int)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::sprintf(const char *s, ...)
+QString &QString::sprintf(const char *, ...)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString QString::lower() const
{
- // FIXME: awaiting real implementation
- QString result(*this);
-
- CFStringLowercase(result.s, NULL);
-
- return result;
+ // FIXME: not yet implemented
+ return QString(*this);
}
QString QString::stripWhiteSpace() const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
QString QString::simplifyWhiteSpace() const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
void QString::compose()
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
QString QString::visual(int index=0, int len=-1)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
+// operators -------------------------------------------------------------------
+
bool QString::operator!() const
{
return isNull();
@@ -409,75 +499,78 @@ QString::operator const char *() const
return latin1();
}
-QChar QString::operator[](int i) const
+QChar QString::operator[](int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-QString &QString::operator+(char c)
+QString &QString::operator+(char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+(QChar c)
+QString &QString::operator+(QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+(const QString &s)
+QString &QString::operator+(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(char c)
+QString &QString::operator+=(char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(QChar c)
+QString &QString::operator+=(QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(const QString &s)
+QString &QString::operator+=(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString::operator QChar() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QChar();
}
+
+// operators associated with QChar and QString =================================
+
/*
-QString &operator+(const char *s1, const QString &s2)
+QString &operator+(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-QString &operator+(QChar c, const QString &s)
+QString &operator+(QChar, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
*/
-bool operator==(const QString &s, QChar c)
+bool operator==(const QString &, QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator==(const QString &s1, const QString &s2)
+bool operator==(const QString &, const QString &)
{
- // FIXME: awaiting real implementation
+#if 0
CFComparisonResult cmp;
int flags;
@@ -486,28 +579,32 @@ bool operator==(const QString &s1, const QString &s2)
cmp = CFStringCompare(s1.s, s2.s, flags);
return (cmp == kCFCompareEqualTo);
+#endif
+ // FIXME: not yet implemented
+ return FALSE;
}
-bool operator==(const QString &s1, const char *s2)
+bool operator==(const QString &, const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator==(const char *s1, const QString &s2)
+bool operator==(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
bool operator!=(const QString &s, QChar c)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator!=(const QString &s1, const QString &s2)
+bool operator!=(const QString &, const QString &)
{
+#if 0
// FIXME: awaiting real implementation
CFComparisonResult cmp;
int flags;
@@ -517,26 +614,34 @@ bool operator!=(const QString &s1, const QString &s2)
cmp = CFStringCompare(s1.s, s2.s, flags);
return (cmp != kCFCompareEqualTo);
+#endif
+ // FIXME: not yet implemented
+ return FALSE;
}
-bool operator!=(const QString &s1, const char *s2)
+bool operator!=(const QString &, const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator!=(const char *s1, const QString &s2)
+bool operator!=(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-QString operator+(char c, const QString &s)
+QString operator+(char, const QString &)
{
- // FIXME: awaiting real implementation
- return FALSE;
+ // FIXME: not yet implemented
+ return QString();
}
+
+// class QConstString ==========================================================
+
+// constructors, copy constructors, and destructors ----------------------------
+
QConstString::QConstString(QChar *qcs, uint len)
{
if (qcs || len) {
@@ -549,6 +654,8 @@ QConstString::QConstString(QChar *qcs, uint len)
}
}
+// member functions ------------------------------------------------------------
+
const QString &QConstString::string() const
{
return *this;
diff --git a/WebCore/kwq/qt/qstring.h b/WebCore/kwq/qt/qstring.h
index 62310e0..7ffa64e 100644
--- a/WebCore/kwq/qt/qstring.h
+++ b/WebCore/kwq/qt/qstring.h
@@ -202,7 +202,6 @@ public:
void truncate(uint pos);
void fill(QChar, int len=-1);
- QString arg (int &);
QString arg(int a, int fieldwidth=0, int base=10) const;
QString arg(const QString &, int fieldwidth=0) const;
@@ -242,6 +241,11 @@ public:
// NOTE: this is NOT private:
CFMutableStringRef s;
+ mutable void *cache;
+ enum CacheType {
+ CacheInvalid, CacheUnicode, CacheLatin1
+ };
+ mutable CacheType cacheType;
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
diff --git a/WebCore/src/kwq/KWQString.mm b/WebCore/src/kwq/KWQString.mm
index 29224fc..70221cb 100644
--- a/WebCore/src/kwq/KWQString.mm
+++ b/WebCore/src/kwq/KWQString.mm
@@ -25,87 +25,126 @@
// FIXME: obviously many functions here can be made inline
+// #include <Foundation/Foundation.h>
#include <qstring.h>
#ifndef USING_BORROWED_QSTRING
+// QString class ===============================================================
+
+// constants -------------------------------------------------------------------
+
const QString QString::null;
-// constructors, copy constructors, and destructors ------------------------
+// constructors, copy constructors, and destructors ----------------------------
QString::QString()
{
s = NULL;
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(QChar qc)
{
s = CFStringCreateMutable(NULL, 0);
- CFStringAppendCharacters(s, &qc.c, 1);
+ if (s) {
+ CFStringAppendCharacters(s, &qc.c, 1);
+ }
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QByteArray &qba)
{
if (qba.size() && *qba.data()) {
s = CFStringCreateMutable(NULL, 0);
- const int capacity = 64;
- UniChar buf[capacity];
- int fill = 0;
- for (uint len = 0; (len < qba.size()) && qba[len]; len++) {
- buf[fill] = qba[len];
- fill++;
- if (fill == capacity) {
+ if (s) {
+ const int capacity = 64;
+ UniChar buf[capacity];
+ int fill = 0;
+ for (uint len = 0; (len < qba.size()) && qba[len]; len++) {
+ buf[fill] = qba[len];
+ fill++;
+ if (fill == capacity) {
+ CFStringAppendCharacters(s, buf, fill);
+ fill = 0;
+ }
+ }
+ if (fill) {
CFStringAppendCharacters(s, buf, fill);
- fill = 0;
}
}
- if (fill) {
- CFStringAppendCharacters(s, buf, fill);
- }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QChar *qcs, uint len)
{
if (qcs || len) {
s = CFStringCreateMutable(NULL, 0);
- CFStringAppendCharacters(s, &qcs->c, len);
+ if (s) {
+ CFStringAppendCharacters(s, &qcs->c, len);
+ }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const char *chs)
{
if (chs && *chs) {
s = CFStringCreateMutable(NULL, 0);
- // FIXME: is ISO Latin-1 the correct encoding?
- CFStringAppendCString(s, chs, kCFStringEncodingISOLatin1);
+ if (s) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ CFStringAppendCString(s, chs, kCFStringEncodingISOLatin1);
+ }
} else {
s = NULL;
}
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::QString(const QString &other)
{
+ // shared copy
+ if (other.s) {
+ CFRetain(other.s);
+ }
s = other.s;
+ cache = NULL;
+ cacheType = CacheInvalid;
}
QString::~QString()
{
- CFRelease(s);
+ if (s) {
+ CFRelease(s);
+ }
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ }
}
-// assignment operators ----------------------------------------------------
+// assignment operators --------------------------------------------------------
QString &QString::operator=(const QString &qs)
{
// shared copy
- CFRetain(qs.s);
- CFRelease(s);
+ if (qs.s) {
+ CFRetain(qs.s);
+ }
+ if (s) {
+ CFRelease(s);
+ }
s = qs.s;
+ cacheType = CacheInvalid;
return *this;
}
@@ -129,276 +168,327 @@ QString &QString::operator=(char ch)
return *this = QString(QChar(ch));
}
-// member functions --------------------------------------------------------
+// member functions ------------------------------------------------------------
-bool QString::isNull() const
+uint QString::length() const
{
- return (s == NULL);
+ return s ? CFStringGetLength(s) : 0;
}
-bool QString::isEmpty() const
+const QChar *QString::unicode() const
{
- return (s == NULL || CFStringGetLength(s) == 0);
+ UniChar *ucs = NULL;
+ uint len = length();
+ if (len) {
+ ucs = const_cast<UniChar *>(CFStringGetCharactersPtr(s));
+ if (!ucs) {
+ // NSLog(@"CFStringGetCharactersPtr returned NULL!!!");
+ if (cacheType != CacheUnicode) {
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ cache = NULL;
+ cacheType = CacheInvalid;
+ }
+ if (!cache) {
+ cache = CFAllocatorAllocate(CFAllocatorGetDefault(),
+ len * sizeof (UniChar), 0);
+ }
+ if (cache) {
+ CFStringGetCharacters(s, CFRangeMake(0, len), cache);
+ cacheType = CacheUnicode;
+ }
+ }
+ ucs = cache;
+ }
+ }
+ // NOTE: this only works since our QChar implementation contains a single
+ // UniChar data member
+ return reinterpret_cast<const QChar *>(ucs);
}
-uint QString::length() const
+const char *QString::latin1() const
{
- return CFStringGetLength(s);
+ char *chs = NULL;
+ uint len = length();
+ if (len) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ chs = const_cast<char *>(CFStringGetCStringPtr(s,
+ kCFStringEncodingISOLatin1));
+ if (!chs) {
+ // NSLog(@"CFStringGetCStringPtr returned NULL!!!");
+ if (cacheType != CacheLatin1) {
+ if (cache) {
+ CFAllocatorDeallocate(CFAllocatorGetDefault(), cache);
+ cache = NULL;
+ cacheType = CacheInvalid;
+ }
+ if (!cache) {
+ cache = CFAllocatorAllocate(CFAllocatorGetDefault(),
+ len + 1, 0);
+ }
+ if (cache) {
+ // FIXME: is ISO Latin-1 the correct encoding?
+ if (!CFStringGetCString(s, cache, len + 1,
+ kCFStringEncodingISOLatin1)) {
+ // NSLog(@"CFStringGetCString returned FALSE!!!");
+ *reinterpret_cast<char *>(cache) = '\0';
+ }
+ cacheType = CacheLatin1;
+ }
+ }
+ chs = cache;
+ }
+ }
+ if (!chs) {
+ static char emptyString[] = "";
+ chs = emptyString;
+ }
+ return chs;
}
-bool QString::startsWith(const QString &s) const
+const char *QString::ascii() const
{
- // FIXME: awaiting real implementation
+ return latin1();
+}
+
+bool QString::isNull() const
+{
+ // NOTE: do NOT use "unicode() == NULL"
+ return s == NULL;
+}
+
+bool QString::isEmpty() const
+{
+ return length() == 0;
+}
+
+bool QString::startsWith(const QString &) const
+{
+ // FIXME: not yet implemented
return FALSE;
}
int QString::toInt() const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::toInt(bool *b, int base=10) const
+int QString::toInt(bool *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-uint QString::toUInt(bool *ok=0, int base=10) const
+uint QString::toUInt(bool *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-long QString::toLong(bool *ok=0, int base=10) const
+long QString::toLong(bool *, int) const
{
- // FIXME: awaiting real implementation
- return 0L;
+ // FIXME: not yet implemented
+ return 0;
}
-float QString::toFloat(bool *b=0) const
+float QString::toFloat(bool *) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0.0f;
}
-QString &QString::prepend(const QString &s)
+QString &QString::prepend(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::append(const char *s)
+QString &QString::append(const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::append(const QString &s)
+QString &QString::append(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-int QString::contains(const char *c, bool cs=TRUE) const
+int QString::contains(const char *, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::contains(char c) const
+int QString::contains(char) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(char c, int index=0) const
+int QString::find(char, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const char *s, int index=0, bool b=0) const
+int QString::find(const char *, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const QString &s, int index=0, bool b=0) const
+int QString::find(const QString &, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::find(const QRegExp &r, int index=0, bool b=0) const
+int QString::find(const QRegExp &, int, bool) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::findRev(char c, int index=0) const
+int QString::findRev(char, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-int QString::findRev(const char *s, int index=0) const
+int QString::findRev(const char *, int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-QString &QString::remove(uint u1, uint u2)
+QString &QString::remove(uint, uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString &QString::replace(const QRegExp &, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::insert(uint i, char c)
+QString &QString::insert(uint, char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-void QString::truncate(uint pos)
+void QString::truncate(uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-void QString::fill(QChar c, int len=-1)
+void QString::fill(QChar, int)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-QString QString::arg(int &a)
+QString QString::arg(int, int, int) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::arg(int a, int fieldwidth=0, int base=10) const
+QString QString::arg(const QString &, int) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::arg(const QString &s, int fieldwidth=0) const
+QString QString::left(uint) const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::left(uint pos) const
+QString QString::right(uint) const
{
- // FIXME: awaiting real implementation
- return *this;
-}
-
-QString QString::right(uint pos) const
-{
- // FIXME: awaiting real implementation
- return *this;
-}
-
-QString QString::mid(int pos, int len=0xffffffff) const
-{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-QString QString::fromLatin1(const char *s, int len=-1)
+QString QString::mid(int, int) const
{
- // FIXME: awaiting real implementation
- return NULL;
+ // FIXME: not yet implemented
+ return QString(*this);
}
-const char *QString::latin1() const
+QString QString::fromLatin1(const char *, int)
{
- // FIXME: awaiting real implementation
- return (const char *)CFStringGetCStringPtr(s, kCFStringEncodingISOLatin1);
-}
-
-const char *QString::ascii() const
-{
- // FIXME: awaiting real implementation
- return NULL;
-}
-
-const QChar *QString::unicode() const
-{
- // FIXME: awaiting real implementation
- return (QChar *)CFStringGetCharactersPtr(s);
+ // FIXME: not yet implemented
+ return QString();
}
QCString QString::utf8() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QCString();
}
QCString QString::local8Bit() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QCString();
}
-QString &QString::setUnicode(const QChar *s, uint i)
+QString &QString::setUnicode(const QChar *, uint)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::setNum(int i, int base=10)
+QString &QString::setNum(int, int)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::sprintf(const char *s, ...)
+QString &QString::sprintf(const char *, ...)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString QString::lower() const
{
- // FIXME: awaiting real implementation
- QString result(*this);
-
- CFStringLowercase(result.s, NULL);
-
- return result;
+ // FIXME: not yet implemented
+ return QString(*this);
}
QString QString::stripWhiteSpace() const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
QString QString::simplifyWhiteSpace() const
{
- // FIXME: awaiting real implementation
- return *this;
+ // FIXME: not yet implemented
+ return QString(*this);
}
void QString::compose()
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
QString QString::visual(int index=0, int len=-1)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
+// operators -------------------------------------------------------------------
+
bool QString::operator!() const
{
return isNull();
@@ -409,75 +499,78 @@ QString::operator const char *() const
return latin1();
}
-QChar QString::operator[](int i) const
+QChar QString::operator[](int) const
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return 0;
}
-QString &QString::operator+(char c)
+QString &QString::operator+(char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+(QChar c)
+QString &QString::operator+(QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+(const QString &s)
+QString &QString::operator+(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(char c)
+QString &QString::operator+=(char)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(QChar c)
+QString &QString::operator+=(QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
-QString &QString::operator+=(const QString &s)
+QString &QString::operator+=(const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return *this;
}
QString::operator QChar() const
{
- // FIXME: awaiting real implementation
- return 0;
+ // FIXME: not yet implemented
+ return QChar();
}
+
+// operators associated with QChar and QString =================================
+
/*
-QString &operator+(const char *s1, const QString &s2)
+QString &operator+(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
-QString &operator+(QChar c, const QString &s)
+QString &operator+(QChar, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
}
*/
-bool operator==(const QString &s, QChar c)
+bool operator==(const QString &, QChar)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator==(const QString &s1, const QString &s2)
+bool operator==(const QString &, const QString &)
{
- // FIXME: awaiting real implementation
+#if 0
CFComparisonResult cmp;
int flags;
@@ -486,28 +579,32 @@ bool operator==(const QString &s1, const QString &s2)
cmp = CFStringCompare(s1.s, s2.s, flags);
return (cmp == kCFCompareEqualTo);
+#endif
+ // FIXME: not yet implemented
+ return FALSE;
}
-bool operator==(const QString &s1, const char *s2)
+bool operator==(const QString &, const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator==(const char *s1, const QString &s2)
+bool operator==(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
bool operator!=(const QString &s, QChar c)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator!=(const QString &s1, const QString &s2)
+bool operator!=(const QString &, const QString &)
{
+#if 0
// FIXME: awaiting real implementation
CFComparisonResult cmp;
int flags;
@@ -517,26 +614,34 @@ bool operator!=(const QString &s1, const QString &s2)
cmp = CFStringCompare(s1.s, s2.s, flags);
return (cmp != kCFCompareEqualTo);
+#endif
+ // FIXME: not yet implemented
+ return FALSE;
}
-bool operator!=(const QString &s1, const char *s2)
+bool operator!=(const QString &, const char *)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-bool operator!=(const char *s1, const QString &s2)
+bool operator!=(const char *, const QString &)
{
- // FIXME: awaiting real implementation
+ // FIXME: not yet implemented
return FALSE;
}
-QString operator+(char c, const QString &s)
+QString operator+(char, const QString &)
{
- // FIXME: awaiting real implementation
- return FALSE;
+ // FIXME: not yet implemented
+ return QString();
}
+
+// class QConstString ==========================================================
+
+// constructors, copy constructors, and destructors ----------------------------
+
QConstString::QConstString(QChar *qcs, uint len)
{
if (qcs || len) {
@@ -549,6 +654,8 @@ QConstString::QConstString(QChar *qcs, uint len)
}
}
+// member functions ------------------------------------------------------------
+
const QString &QConstString::string() const
{
return *this;
diff --git a/WebCore/src/kwq/qt/qstring.h b/WebCore/src/kwq/qt/qstring.h
index 62310e0..7ffa64e 100644
--- a/WebCore/src/kwq/qt/qstring.h
+++ b/WebCore/src/kwq/qt/qstring.h
@@ -202,7 +202,6 @@ public:
void truncate(uint pos);
void fill(QChar, int len=-1);
- QString arg (int &);
QString arg(int a, int fieldwidth=0, int base=10) const;
QString arg(const QString &, int fieldwidth=0) const;
@@ -242,6 +241,11 @@ public:
// NOTE: this is NOT private:
CFMutableStringRef s;
+ mutable void *cache;
+ enum CacheType {
+ CacheInvalid, CacheUnicode, CacheLatin1
+ };
+ mutable CacheType cacheType;
// protected -------------------------------------------------------------------
// private ---------------------------------------------------------------------
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list