[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:50:36 UTC 2009
The following commit has been merged in the debian/unstable branch:
commit 896cd52337cdcd66ec69ca32d7ba61d2dd7faa48
Author: gramps <gramps at 268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date: Wed Oct 17 20:01:22 2001 +0000
Added fromStringWithEncoding for QTextCodec implementation
git-svn-id: http://svn.webkit.org/repository/webkit/trunk@343 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/kwq/KWQString.h b/WebCore/kwq/KWQString.h
index 63ad48b..9f6c810 100644
--- a/WebCore/kwq/KWQString.h
+++ b/WebCore/kwq/KWQString.h
@@ -193,6 +193,7 @@ public:
#ifdef USING_BORROWED_KURL
static QString fromLocal8Bit(const char *, int len=-1);
#endif
+ static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
// constructors, copy constructors, and destructors ------------------------
diff --git a/WebCore/kwq/KWQString.mm b/WebCore/kwq/KWQString.mm
index e707b3c..245bdf0 100644
--- a/WebCore/kwq/KWQString.mm
+++ b/WebCore/kwq/KWQString.mm
@@ -83,19 +83,33 @@ QString QString::fromLatin1(const char *chs)
#ifdef USING_BORROWED_KURL
QString QString::fromLocal8Bit(const char *chs, int len)
{
+ // FIXME: is MacRoman the correct encoding?
+ return fromStringWithEncoding(chs, len, kCFStringEncodingMacRoman);
+}
+#endif // USING_BORROWED_KURL
+
+QString QString::fromStringWithEncoding(const char *chs, int len,
+ CFStringEncoding encoding)
+{
QString qs;
if (chs && *chs) {
qs.s = CFStringCreateMutable(kCFAllocatorDefault, 0);
if (qs.s) {
if (len < 0) {
// append null-terminated string
- // FIXME: is MacRoman the correct encoding?
- CFStringAppendCString(qs.s, chs, kCFStringEncodingMacRoman);
+ CFStringAppendCString(qs.s, chs, encoding);
} else {
// append length-specified string
- // FIXME: this uses code similar to that in the
- // "QString(const QByteArray &)" constructor and could possibly
- // be refactored
+ // FIXME: can we find some way of not using this temporary?
+#if 1
+ char *buf = CFAllocatorAllocate(kCFAllocatorDefault, len + 1, 0);
+ if (buf) {
+ strncpy(buf, chs, len);
+ *(buf + len) = '\0';
+ CFStringAppendCString(qs.s, buf, encoding);
+ CFAllocatorDeallocate(kCFAllocatorDefault, buf);
+ }
+#else
const int capacity = 64;
UniChar buf[capacity];
int fill = 0;
@@ -111,12 +125,12 @@ QString QString::fromLocal8Bit(const char *chs, int len)
if (fill) {
CFStringAppendCharacters(qs.s, buf, fill);
}
+#endif
}
}
}
return qs;
}
-#endif // USING_BORROWED_KURL
QString QString::fromCFMutableString(CFMutableStringRef cfs)
{
@@ -155,8 +169,6 @@ QString::QString(const QByteArray &qba)
if (qba.size() && *qba.data()) {
s = CFStringCreateMutable(kCFAllocatorDefault, 0);
if (s) {
- // FIXME: this uses code similar to that in the "fromLocal8Bit"
- // function and could possibly be refactored
const int capacity = 64;
UniChar buf[capacity];
int fill = 0;
diff --git a/WebCore/kwq/qt/qstring.h b/WebCore/kwq/qt/qstring.h
index 63ad48b..9f6c810 100644
--- a/WebCore/kwq/qt/qstring.h
+++ b/WebCore/kwq/qt/qstring.h
@@ -193,6 +193,7 @@ public:
#ifdef USING_BORROWED_KURL
static QString fromLocal8Bit(const char *, int len=-1);
#endif
+ static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
// constructors, copy constructors, and destructors ------------------------
diff --git a/WebCore/src/kwq/KWQString.mm b/WebCore/src/kwq/KWQString.mm
index e707b3c..245bdf0 100644
--- a/WebCore/src/kwq/KWQString.mm
+++ b/WebCore/src/kwq/KWQString.mm
@@ -83,19 +83,33 @@ QString QString::fromLatin1(const char *chs)
#ifdef USING_BORROWED_KURL
QString QString::fromLocal8Bit(const char *chs, int len)
{
+ // FIXME: is MacRoman the correct encoding?
+ return fromStringWithEncoding(chs, len, kCFStringEncodingMacRoman);
+}
+#endif // USING_BORROWED_KURL
+
+QString QString::fromStringWithEncoding(const char *chs, int len,
+ CFStringEncoding encoding)
+{
QString qs;
if (chs && *chs) {
qs.s = CFStringCreateMutable(kCFAllocatorDefault, 0);
if (qs.s) {
if (len < 0) {
// append null-terminated string
- // FIXME: is MacRoman the correct encoding?
- CFStringAppendCString(qs.s, chs, kCFStringEncodingMacRoman);
+ CFStringAppendCString(qs.s, chs, encoding);
} else {
// append length-specified string
- // FIXME: this uses code similar to that in the
- // "QString(const QByteArray &)" constructor and could possibly
- // be refactored
+ // FIXME: can we find some way of not using this temporary?
+#if 1
+ char *buf = CFAllocatorAllocate(kCFAllocatorDefault, len + 1, 0);
+ if (buf) {
+ strncpy(buf, chs, len);
+ *(buf + len) = '\0';
+ CFStringAppendCString(qs.s, buf, encoding);
+ CFAllocatorDeallocate(kCFAllocatorDefault, buf);
+ }
+#else
const int capacity = 64;
UniChar buf[capacity];
int fill = 0;
@@ -111,12 +125,12 @@ QString QString::fromLocal8Bit(const char *chs, int len)
if (fill) {
CFStringAppendCharacters(qs.s, buf, fill);
}
+#endif
}
}
}
return qs;
}
-#endif // USING_BORROWED_KURL
QString QString::fromCFMutableString(CFMutableStringRef cfs)
{
@@ -155,8 +169,6 @@ QString::QString(const QByteArray &qba)
if (qba.size() && *qba.data()) {
s = CFStringCreateMutable(kCFAllocatorDefault, 0);
if (s) {
- // FIXME: this uses code similar to that in the "fromLocal8Bit"
- // function and could possibly be refactored
const int capacity = 64;
UniChar buf[capacity];
int fill = 0;
diff --git a/WebCore/src/kwq/qt/qstring.h b/WebCore/src/kwq/qt/qstring.h
index 63ad48b..9f6c810 100644
--- a/WebCore/src/kwq/qt/qstring.h
+++ b/WebCore/src/kwq/qt/qstring.h
@@ -193,6 +193,7 @@ public:
#ifdef USING_BORROWED_KURL
static QString fromLocal8Bit(const char *, int len=-1);
#endif
+ static QString fromStringWithEncoding(const char *, int, CFStringEncoding);
static QString fromCFMutableString(CFMutableStringRef);
// constructors, copy constructors, and destructors ------------------------
--
WebKit Debian packaging
More information about the Pkg-webkit-commits
mailing list