summaryrefslogtreecommitdiffstats
path: root/WebCore/platform/text
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2010-10-22 13:02:20 +0100
committerBen Murdoch <benm@google.com>2010-10-26 15:21:41 +0100
commita94275402997c11dd2e778633dacf4b7e630a35d (patch)
treee66f56c67e3b01f22c9c23cd932271ee9ac558ed /WebCore/platform/text
parent09e26c78506587b3f5d930d7bc72a23287ffbec0 (diff)
downloadexternal_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.zip
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.gz
external_webkit-a94275402997c11dd2e778633dacf4b7e630a35d.tar.bz2
Merge WebKit at r70209: Initial merge by Git
Change-Id: Id23a68efa36e9d1126bcce0b137872db00892c8e
Diffstat (limited to 'WebCore/platform/text')
-rw-r--r--WebCore/platform/text/Base64.cpp77
-rw-r--r--WebCore/platform/text/Base64.h12
-rw-r--r--WebCore/platform/text/LineEnding.cpp135
-rw-r--r--WebCore/platform/text/LineEnding.h19
-rw-r--r--WebCore/platform/text/StringBuffer.h35
-rw-r--r--WebCore/platform/text/StringBuilder.cpp132
-rw-r--r--WebCore/platform/text/StringBuilder.h69
-rw-r--r--WebCore/platform/text/TextEncoding.cpp4
-rw-r--r--WebCore/platform/text/TextEncodingRegistry.cpp9
-rw-r--r--WebCore/platform/text/brew/TextBoundariesBrew.cpp74
-rw-r--r--WebCore/platform/text/brew/TextBreakIteratorBrew.cpp312
-rw-r--r--WebCore/platform/text/brew/TextCodecBrew.cpp214
-rw-r--r--WebCore/platform/text/brew/TextCodecBrew.h61
-rw-r--r--WebCore/platform/text/qt/TextBreakIteratorQt.cpp7
-rw-r--r--WebCore/platform/text/wince/TextCodecWinCE.cpp3
15 files changed, 858 insertions, 305 deletions
diff --git a/WebCore/platform/text/Base64.cpp b/WebCore/platform/text/Base64.cpp
index cc22cf8..98b537a 100644
--- a/WebCore/platform/text/Base64.cpp
+++ b/WebCore/platform/text/Base64.cpp
@@ -2,6 +2,7 @@
Copyright (C) 2000-2001 Dawit Alemayehu <adawit@kde.org>
Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
Copyright (C) 2007, 2008 Apple Inc. All rights reserved.
+ Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License (LGPL)
@@ -25,6 +26,7 @@
#include <limits.h>
#include <wtf/StringExtras.h>
+#include <wtf/text/WTFString.h>
namespace WebCore {
@@ -70,7 +72,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
return;
// If the input string is pathologically large, just return nothing.
- // Note: Keep this in sync with the "out_len" computation below.
+ // Note: Keep this in sync with the "outLength" computation below.
// Rather than being perfectly precise, this is a bit conservative.
const unsigned maxInputBufferSize = UINT_MAX / 77 * 76 / 4 * 3 - 2;
if (len > maxInputBufferSize)
@@ -79,21 +81,21 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
unsigned sidx = 0;
unsigned didx = 0;
- unsigned out_len = ((len + 2) / 3) * 4;
+ unsigned outLength = ((len + 2) / 3) * 4;
// Deal with the 76 character per line limit specified in RFC 2045.
- insertLFs = (insertLFs && out_len > 76);
+ insertLFs = (insertLFs && outLength > 76);
if (insertLFs)
- out_len += ((out_len - 1) / 76);
+ outLength += ((outLength - 1) / 76);
int count = 0;
- out.grow(out_len);
+ out.grow(outLength);
// 3-byte to 4-byte conversion + 0-63 to ascii printable conversion
if (len > 1) {
while (sidx < len - 2) {
if (insertLFs) {
- if (count && (count % 76) == 0)
+ if (count && !(count % 76))
out[didx++] = '\n';
count += 4;
}
@@ -106,7 +108,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
}
if (sidx < len) {
- if (insertLFs && (count > 0) && (count % 76) == 0)
+ if (insertLFs && (count > 0) && !(count % 76))
out[didx++] = '\n';
out[didx++] = base64EncMap[(data[sidx] >> 2) & 077];
@@ -124,7 +126,7 @@ void base64Encode(const char* data, unsigned len, Vector<char>& out, bool insert
}
}
-bool base64Decode(const Vector<char>& in, Vector<char>& out)
+bool base64Decode(const Vector<char>& in, Vector<char>& out, Base64DecodePolicy policy)
{
out.clear();
@@ -132,36 +134,49 @@ bool base64Decode(const Vector<char>& in, Vector<char>& out)
if (in.size() > UINT_MAX)
return false;
- return base64Decode(in.data(), in.size(), out);
+ return base64Decode(in.data(), in.size(), out, policy);
}
-bool base64Decode(const char* data, unsigned len, Vector<char>& out)
+template<typename T>
+static inline bool base64DecodeInternal(const T* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
{
out.clear();
- if (len == 0)
+ if (!len)
return true;
- while (len && data[len-1] == '=')
- --len;
-
out.grow(len);
+
+ bool sawEqualsSign = false;
+ unsigned outLength = 0;
for (unsigned idx = 0; idx < len; idx++) {
- unsigned char ch = data[idx];
- if ((ch > 47 && ch < 58) || (ch > 64 && ch < 91) || (ch > 96 && ch < 123) || ch == '+' || ch == '/' || ch == '=')
- out[idx] = base64DecMap[ch];
- else
+ unsigned ch = data[idx];
+ if (ch == '=')
+ sawEqualsSign = true;
+ else if (('0' <= ch && ch <= '9') || ('A' <= ch && ch <= 'Z') || ('a' <= ch && ch <= 'z') || ch == '+' || ch == '/') {
+ if (sawEqualsSign)
+ return false;
+ out[outLength] = base64DecMap[ch];
+ outLength++;
+ } else if (policy == FailOnInvalidCharacter || (policy == IgnoreWhitespace && !isSpaceOrNewline(ch)))
return false;
}
+ if (!outLength)
+ return !sawEqualsSign;
+
+ // Valid data is (n * 4 + [0,2,3]) characters long.
+ if ((outLength % 4) == 1)
+ return false;
+
// 4-byte to 3-byte conversion
- unsigned outLen = len - ((len + 3) / 4);
- if (!outLen || ((outLen + 2) / 3) * 4 < len)
+ outLength -= (outLength + 3) / 4;
+ if (!outLength)
return false;
unsigned sidx = 0;
unsigned didx = 0;
- if (outLen > 1) {
- while (didx < outLen - 2) {
+ if (outLength > 1) {
+ while (didx < outLength - 2) {
out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
out[didx + 1] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
out[didx + 2] = (((out[sidx + 2] << 6) & 255) | (out[sidx + 3] & 077));
@@ -170,16 +185,26 @@ bool base64Decode(const char* data, unsigned len, Vector<char>& out)
}
}
- if (didx < outLen)
+ if (didx < outLength)
out[didx] = (((out[sidx] << 2) & 255) | ((out[sidx + 1] >> 4) & 003));
- if (++didx < outLen)
+ if (++didx < outLength)
out[didx] = (((out[sidx + 1] << 4) & 255) | ((out[sidx + 2] >> 2) & 017));
- if (outLen < out.size())
- out.shrink(outLen);
+ if (outLength < out.size())
+ out.shrink(outLength);
return true;
}
+bool base64Decode(const char* data, unsigned len, Vector<char>& out, Base64DecodePolicy policy)
+{
+ return base64DecodeInternal<char>(data, len, out, policy);
}
+
+bool base64Decode(const String& in, Vector<char>& out, Base64DecodePolicy policy)
+{
+ return base64DecodeInternal<UChar>(in.characters(), in.length(), out, policy);
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/Base64.h b/WebCore/platform/text/Base64.h
index 53b29b0..211bd3c 100644
--- a/WebCore/platform/text/Base64.h
+++ b/WebCore/platform/text/Base64.h
@@ -1,5 +1,6 @@
/*
- * Copyright (C) 2006 Alexey Proskuryakov (ap@webkit.org)
+ * Copyright (C) 2006 Alexey Proskuryakov <ap@webkit.org>
+ * Copyright (C) 2010 Patrick Gansterer <paroga@paroga.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -26,16 +27,19 @@
#ifndef Base64_h
#define Base64_h
+#include <wtf/Forward.h>
#include <wtf/Vector.h>
namespace WebCore {
+enum Base64DecodePolicy { FailOnInvalidCharacter, IgnoreWhitespace, IgnoreInvalidCharacters };
+
void base64Encode(const Vector<char>&, Vector<char>&, bool insertLFs = false);
void base64Encode(const char*, unsigned, Vector<char>&, bool insertLFs = false);
-// this decoder is not general purpose - it returns an error if it encounters a linefeed, as needed for window.atob
-bool base64Decode(const Vector<char>&, Vector<char>&);
-bool base64Decode(const char*, unsigned, Vector<char>&);
+bool base64Decode(const String&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
+bool base64Decode(const Vector<char>&, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
+bool base64Decode(const char*, unsigned, Vector<char>&, Base64DecodePolicy = FailOnInvalidCharacter);
}
diff --git a/WebCore/platform/text/LineEnding.cpp b/WebCore/platform/text/LineEnding.cpp
index 545f22b..00a90eb 100644
--- a/WebCore/platform/text/LineEnding.cpp
+++ b/WebCore/platform/text/LineEnding.cpp
@@ -35,12 +35,69 @@
#include "PlatformString.h"
#include <wtf/text/CString.h>
-namespace WebCore {
+namespace {
-// Normalize all line-endings to CRLF.
-CString normalizeLineEndingsToCRLF(const CString& from)
+class OutputBuffer {
+public:
+ virtual char* allocate(size_t size) = 0;
+ virtual void copy(const CString&) = 0;
+ virtual ~OutputBuffer() { }
+};
+
+class CStringBuffer : public OutputBuffer {
+public:
+ CStringBuffer(CString& buffer)
+ : m_buffer(buffer)
+ {
+ }
+ virtual ~CStringBuffer() { }
+
+ virtual char* allocate(size_t size)
+ {
+ char* ptr;
+ m_buffer = CString::newUninitialized(size, ptr);
+ return ptr;
+ }
+
+ virtual void copy(const CString& source)
+ {
+ m_buffer = source;
+ }
+
+ const CString& buffer() const { return m_buffer; }
+
+private:
+ CString m_buffer;
+};
+
+class VectorCharAppendBuffer : public OutputBuffer {
+public:
+ VectorCharAppendBuffer(Vector<char>& buffer)
+ : m_buffer(buffer)
+ {
+ }
+ virtual ~VectorCharAppendBuffer() { }
+
+ virtual char* allocate(size_t size)
+ {
+ size_t oldSize = m_buffer.size();
+ m_buffer.grow(oldSize + size);
+ return m_buffer.data() + oldSize;
+ }
+
+ virtual void copy(const CString& source)
+ {
+ m_buffer.append(source.data(), source.length());
+ }
+
+private:
+ Vector<char>& m_buffer;
+};
+
+void internalNormalizeLineEndingsToCRLF(const CString& from, OutputBuffer& buffer)
{
- unsigned newLen = 0;
+ // Compute the new length.
+ size_t newLen = 0;
const char* p = from.data();
while (char c = *p++) {
if (c == '\r') {
@@ -57,13 +114,18 @@ CString normalizeLineEndingsToCRLF(const CString& from)
newLen += 1;
}
}
- if (newLen == from.length())
- return from;
+ if (newLen < from.length())
+ return;
+
+ if (newLen == from.length()) {
+ buffer.copy(from);
+ return;
+ }
- // Make a copy of the string.
p = from.data();
- char* q;
- CString result = CString::newUninitialized(newLen, q);
+ char* q = buffer.allocate(newLen);
+
+ // Make a copy of the string.
while (char c = *p++) {
if (c == '\r') {
// Safe to look ahead because of trailing '\0'.
@@ -81,13 +143,19 @@ CString normalizeLineEndingsToCRLF(const CString& from)
*q++ = c;
}
}
- return result;
}
+};
+
+namespace WebCore {
+
+void normalizeToCROrLF(const CString& from, Vector<char>& result, bool toCR);
+
// Normalize all line-endings to CR or LF.
-static CString normalizeToCROrLF(const CString& from, bool toCR)
+void normalizeToCROrLF(const CString& from, Vector<char>& result, bool toCR)
{
- unsigned newLen = 0;
+ // Compute the new length.
+ size_t newLen = 0;
bool needFix = false;
const char* p = from.data();
char fromEndingChar = toCR ? '\n' : '\r';
@@ -103,13 +171,20 @@ static CString normalizeToCROrLF(const CString& from, bool toCR)
}
newLen += 1;
}
- if (!needFix)
- return from;
- // Make a copy of the string.
+ // Grow the result buffer.
p = from.data();
- char* q;
- CString result = CString::newUninitialized(newLen, q);
+ size_t oldResultSize = result.size();
+ result.grow(oldResultSize + newLen);
+ char* q = result.data() + oldResultSize;
+
+ // If no need to fix the string, just copy the string over.
+ if (!needFix) {
+ memcpy(q, p, from.length());
+ return;
+ }
+
+ // Make a copy of the string.
while (char c = *p++) {
if (c == '\r' && *p == '\n') {
// Turn CRLF or CR into CR or LF.
@@ -123,27 +198,33 @@ static CString normalizeToCROrLF(const CString& from, bool toCR)
*q++ = c;
}
}
- return result;
}
-// Normalize all line-endings to CR.
-CString normalizeLineEndingsToCR(const CString& from)
+CString normalizeLineEndingsToCRLF(const CString& from)
+{
+ CString result;
+ CStringBuffer buffer(result);
+ internalNormalizeLineEndingsToCRLF(from, buffer);
+ return buffer.buffer();
+}
+
+void normalizeLineEndingsToCR(const CString& from, Vector<char>& result)
{
- return normalizeToCROrLF(from, true);
+ normalizeToCROrLF(from, result, true);
}
-// Normalize all line-endings to LF.
-CString normalizeLineEndingsToLF(const CString& from)
+void normalizeLineEndingsToLF(const CString& from, Vector<char>& result)
{
- return normalizeToCROrLF(from, false);
+ normalizeToCROrLF(from, result, false);
}
-CString normalizeLineEndingsToNative(const CString& from)
+void normalizeLineEndingsToNative(const CString& from, Vector<char>& result)
{
#if OS(WINDOWS)
- return normalizeLineEndingsToCRLF(from);
+ VectorCharAppendBuffer buffer(result);
+ internalNormalizeLineEndingsToCRLF(from, buffer);
#else
- return normalizeLineEndingsToLF(from);
+ normalizeLineEndingsToLF(from, result);
#endif
}
diff --git a/WebCore/platform/text/LineEnding.h b/WebCore/platform/text/LineEnding.h
index ab8d6ee..4306ce8 100644
--- a/WebCore/platform/text/LineEnding.h
+++ b/WebCore/platform/text/LineEnding.h
@@ -33,25 +33,22 @@
#define LineEnding_h
#include <wtf/Forward.h>
-
-namespace WTF {
-class CString;
-}
+#include <wtf/Vector.h>
namespace WebCore {
// Normalize all line-endings in the given string to CRLF.
-WTF::CString normalizeLineEndingsToCRLF(const WTF::CString&);
+CString normalizeLineEndingsToCRLF(const CString& from);
-// Normalize all line-endings in the given string to CR.
-WTF::CString normalizeLineEndingsToCR(const WTF::CString&);
+// Normalize all line-endings in the given string to CR and append the result to the given buffer.
+void normalizeLineEndingsToCR(const CString& from, Vector<char>& result);
-// Normalize all line-endings in the given string to LF.
-WTF::CString normalizeLineEndingsToLF(const WTF::CString&);
+// Normalize all line-endings in the given string to LF and append the result to the given buffer.
+void normalizeLineEndingsToLF(const CString& from, Vector<char>& result);
-// Normalize all line-endings in the given string to the native line-endings.
+// Normalize all line-endings in the given string to the native line-endings and append the result to the given buffer.
// (Normalize to CRLF on Windows and normalize to LF on all other platforms.)
-WTF::CString normalizeLineEndingsToNative(const WTF::CString&);
+void normalizeLineEndingsToNative(const CString& from, Vector<char>& result);
} // namespace WebCore
diff --git a/WebCore/platform/text/StringBuffer.h b/WebCore/platform/text/StringBuffer.h
deleted file mode 100644
index 3a753b4..0000000
--- a/WebCore/platform/text/StringBuffer.h
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Inc. ("Apple") nor the names of its
- * contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef WebCoreStringBuffer_h
-#define WebCoreStringBuffer_h
-
-// FIXME: remove this header, use the forward from wtf directly.
-#include <wtf/text/StringBuffer.h>
-
-#endif // StringBuffer_h
diff --git a/WebCore/platform/text/StringBuilder.cpp b/WebCore/platform/text/StringBuilder.cpp
deleted file mode 100644
index 1c47129..0000000
--- a/WebCore/platform/text/StringBuilder.cpp
+++ /dev/null
@@ -1,132 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
- * Copyright (C) Research In Motion Limited 2010. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#include "config.h"
-#include "StringBuilder.h"
-
-#include <wtf/text/StringBuffer.h>
-
-namespace WebCore {
-
-void StringBuilder::append(const String& string)
-{
- if (string.isNull())
- return;
-
- if (m_totalLength == UINT_MAX)
- m_totalLength = string.length();
- else
- m_totalLength += string.length();
-
- if (!string.isEmpty())
- m_strings.append(string);
-}
-
-void StringBuilder::append(UChar c)
-{
- if (m_totalLength == UINT_MAX)
- m_totalLength = 1;
- else
- m_totalLength += 1;
-
- m_strings.append(String(&c, 1));
-}
-
-void StringBuilder::append(char c)
-{
- if (m_totalLength == UINT_MAX)
- m_totalLength = 1;
- else
- m_totalLength += 1;
-
- m_strings.append(String(&c, 1));
-}
-
-String StringBuilder::toString(ConcatMode mode) const
-{
- if (isNull())
- return String();
-
- unsigned count = m_strings.size();
-
- if (!count)
- return String(StringImpl::empty());
- if (count == 1)
- return m_strings[0];
-
- UChar* buffer;
- unsigned totalLength = m_totalLength;
- if (mode == ConcatAddingSpacesBetweenIndividualStrings)
- totalLength += count - 1;
- String result = String::createUninitialized(totalLength, buffer);
-
- UChar* p = buffer;
-
- // We could handle both Concat modes in a single for loop, not doing that for performance reasons.
- if (mode == ConcatUnaltered) {
- for (unsigned i = 0; i < count; ++i) {
- StringImpl* string = m_strings[i].impl();
- unsigned length = string->length();
- memcpy(p, string->characters(), length * 2);
- p += length;
- }
- } else {
- ASSERT(mode == ConcatAddingSpacesBetweenIndividualStrings);
- for (unsigned i = 0; i < count; ++i) {
- StringImpl* string = m_strings[i].impl();
- unsigned length = string->length();
- memcpy(p, string->characters(), length * 2);
- p += length;
-
- // Add space after string before the start of the next string, if we're not processing the last string.
- if (i < count - 1) {
- *p = ' ';
- ++p;
- }
- }
- }
- ASSERT(p == totalLength + buffer);
-
- return result;
-}
-
-void StringBuilder::clear()
-{
- m_totalLength = UINT_MAX;
- m_strings.clear();
-}
-
-unsigned StringBuilder::length() const
-{
- if (m_totalLength == UINT_MAX)
- return 0;
- return m_totalLength;
-}
-
-}
diff --git a/WebCore/platform/text/StringBuilder.h b/WebCore/platform/text/StringBuilder.h
deleted file mode 100644
index 72adfa7..0000000
--- a/WebCore/platform/text/StringBuilder.h
+++ /dev/null
@@ -1,69 +0,0 @@
-/*
- * Copyright (C) 2008 Apple Inc. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- *
- * 1. Redistributions of source code must retain the above copyright
- * notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- * notice, this list of conditions and the following disclaimer in the
- * documentation and/or other materials provided with the distribution.
- * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of
- * its contributors may be used to endorse or promote products derived
- * from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
- * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
- * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
- * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-#ifndef StringBuilder_h
-#define StringBuilder_h
-
-#include "PlatformString.h"
-
-namespace WebCore {
-
-enum ConcatMode {
- ConcatUnaltered,
- ConcatAddingSpacesBetweenIndividualStrings
-};
-
-class StringBuilder {
-public:
- StringBuilder() : m_totalLength(UINT_MAX) {}
-
- void setNonNull()
- {
- if (m_totalLength == UINT_MAX)
- m_totalLength = 0;
- }
-
- void append(const String&);
- void append(UChar);
- void append(char);
-
- void clear();
- unsigned length() const;
-
- String toString(ConcatMode mode = ConcatUnaltered) const;
-
-private:
- bool isNull() const { return m_totalLength == UINT_MAX; }
-
- unsigned m_totalLength;
- Vector<String, 16> m_strings;
-};
-
-}
-
-#endif
diff --git a/WebCore/platform/text/TextEncoding.cpp b/WebCore/platform/text/TextEncoding.cpp
index 29ae170..921ceeb 100644
--- a/WebCore/platform/text/TextEncoding.cpp
+++ b/WebCore/platform/text/TextEncoding.cpp
@@ -133,6 +133,10 @@ CString TextEncoding::encode(const UChar* characters, size_t length, Unencodable
// normalization will be done by Windows CE API
OwnPtr<TextCodec> textCodec = newTextCodec(*this);
return textCodec.get() ? textCodec->encode(characters, length, handling) : CString();
+#elif USE(BREWMP_UNICODE)
+ // FIXME: not sure if Brew MP normalizes the input string automatically
+ OwnPtr<TextCodec> textCodec = newTextCodec(*this);
+ return textCodec.get() ? textCodec->encode(characters, length, handling) : CString();
#endif
}
diff --git a/WebCore/platform/text/TextEncodingRegistry.cpp b/WebCore/platform/text/TextEncodingRegistry.cpp
index 40fcdc5..fbe5826 100644
--- a/WebCore/platform/text/TextEncodingRegistry.cpp
+++ b/WebCore/platform/text/TextEncodingRegistry.cpp
@@ -31,6 +31,7 @@
#include "TextCodecLatin1.h"
#include "TextCodecUserDefined.h"
#include "TextCodecUTF16.h"
+#include "TextEncoding.h"
#include <wtf/ASCIICType.h>
#include <wtf/Assertions.h>
#include <wtf/HashFunctions.h>
@@ -51,6 +52,9 @@
#if USE(GLIB_UNICODE)
#include "gtk/TextCodecGtk.h"
#endif
+#if USE(BREWMP_UNICODE)
+#include "brew/TextCodecBrew.h"
+#endif
#if OS(WINCE) && !PLATFORM(QT)
#include "TextCodecWinCE.h"
#endif
@@ -235,6 +239,11 @@ static void buildBaseTextCodecMaps()
TextCodecGtk::registerBaseCodecs(addToTextCodecMap);
#endif
+#if USE(BREWMP_UNICODE)
+ TextCodecBrew::registerBaseEncodingNames(addToTextEncodingNameMap);
+ TextCodecBrew::registerBaseCodecs(addToTextCodecMap);
+#endif
+
#if OS(WINCE) && !PLATFORM(QT)
TextCodecWinCE::registerBaseEncodingNames(addToTextEncodingNameMap);
TextCodecWinCE::registerBaseCodecs(addToTextCodecMap);
diff --git a/WebCore/platform/text/brew/TextBoundariesBrew.cpp b/WebCore/platform/text/brew/TextBoundariesBrew.cpp
new file mode 100644
index 0000000..506bdcf
--- /dev/null
+++ b/WebCore/platform/text/brew/TextBoundariesBrew.cpp
@@ -0,0 +1,74 @@
+/*
+ * Copyright (C) 2006 Zack Rusin <zack@kde.org>
+ * Copyright (C) 2007-2009 Torch Mobile, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextBoundaries.h"
+
+#include "NotImplemented.h"
+#include "PlatformString.h"
+
+using namespace WTF::Unicode;
+
+namespace WebCore {
+
+int findNextWordFromIndex(const UChar* buffer, int len, int position, bool forward)
+{
+ notImplemented();
+ return 0;
+}
+
+void findWordBoundary(const UChar* buffer, int len, int position, int* start, int* end)
+{
+ if (position > len) {
+ *start = 0;
+ *end = 0;
+ return;
+ }
+
+ String str(buffer, len);
+
+ int currentPosition = position - 1;
+ String foundWord;
+ while (currentPosition >= 0 && isLetter(str[currentPosition])) {
+ UChar c = str[currentPosition];
+ foundWord.insert(&c, 1, 0);
+ --currentPosition;
+ }
+
+ // currentPosition == 0 means the first char is not letter
+ // currentPosition == -1 means we reached the beginning
+ int startPos = (currentPosition < 0) ? 0 : ++currentPosition;
+ currentPosition = position;
+ while (isLetter(str[currentPosition])) {
+ foundWord.append(str[currentPosition]);
+ ++currentPosition;
+ }
+
+ *start = startPos;
+ *end = currentPosition;
+}
+
+}
diff --git a/WebCore/platform/text/brew/TextBreakIteratorBrew.cpp b/WebCore/platform/text/brew/TextBreakIteratorBrew.cpp
new file mode 100644
index 0000000..7f46e4f
--- /dev/null
+++ b/WebCore/platform/text/brew/TextBreakIteratorBrew.cpp
@@ -0,0 +1,312 @@
+/*
+ * Copyright (C) 2006 Lars Knoll <lars@trolltech.com>
+ * Copyright (C) 2007-2009 Torch Mobile, Inc.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public License
+ * along with this library; see the file COPYING.LIB. If not, write to
+ * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ * Boston, MA 02111-1307, USA.
+ *
+ */
+
+#include "config.h"
+#include "TextBreakIterator.h"
+
+#include "PlatformString.h"
+#include <wtf/StdLibExtras.h>
+#include <wtf/unicode/Unicode.h>
+
+using namespace WTF::Unicode;
+
+namespace WebCore {
+
+// Hack, not entirely correct
+static inline bool isCharStop(UChar c)
+{
+ CharCategory charCategory = category(c);
+ return charCategory != Mark_NonSpacing && (charCategory != Other_Surrogate || (c < 0xd800 || c >= 0xdc00));
+}
+
+static inline bool isLineStop(UChar c)
+{
+ return category(c) != Separator_Line;
+}
+
+static inline bool isSentenceStop(UChar c)
+{
+ return isPunct(c);
+}
+
+class TextBreakIterator {
+public:
+ void reset(const UChar* str, int len)
+ {
+ string = str;
+ length = len;
+ currentPos = 0;
+ }
+ virtual int first() = 0;
+ virtual int next() = 0;
+ virtual int previous() = 0;
+ int following(int position)
+ {
+ currentPos = position;
+ return next();
+ }
+ int preceding(int position)
+ {
+ currentPos = position;
+ return previous();
+ }
+
+ int currentPos;
+ const UChar* string;
+ int length;
+};
+
+struct WordBreakIterator: TextBreakIterator {
+ virtual int first();
+ virtual int next();
+ virtual int previous();
+};
+
+struct CharBreakIterator: TextBreakIterator {
+ virtual int first();
+ virtual int next();
+ virtual int previous();
+};
+
+struct LineBreakIterator: TextBreakIterator {
+ virtual int first();
+ virtual int next();
+ virtual int previous();
+};
+
+struct SentenceBreakIterator : TextBreakIterator {
+ virtual int first();
+ virtual int next();
+ virtual int previous();
+};
+
+int WordBreakIterator::first()
+{
+ currentPos = 0;
+ return currentPos;
+}
+
+int WordBreakIterator::next()
+{
+ if (currentPos == length) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos < length) {
+ if (haveSpace && !isSpace(string[currentPos]))
+ break;
+ if (isSpace(string[currentPos]))
+ haveSpace = true;
+ ++currentPos;
+ }
+ return currentPos;
+}
+
+int WordBreakIterator::previous()
+{
+ if (!currentPos) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos > 0) {
+ if (haveSpace && !isSpace(string[currentPos]))
+ break;
+ if (isSpace(string[currentPos]))
+ haveSpace = true;
+ --currentPos;
+ }
+ return currentPos;
+}
+
+int CharBreakIterator::first()
+{
+ currentPos = 0;
+ return currentPos;
+}
+
+int CharBreakIterator::next()
+{
+ if (currentPos >= length)
+ return -1;
+ ++currentPos;
+ while (currentPos < length && !isCharStop(string[currentPos]))
+ ++currentPos;
+ return currentPos;
+}
+
+int CharBreakIterator::previous()
+{
+ if (currentPos <= 0)
+ return -1;
+ if (currentPos > length)
+ currentPos = length;
+ --currentPos;
+ while (currentPos > 0 && !isCharStop(string[currentPos]))
+ --currentPos;
+ return currentPos;
+}
+
+int LineBreakIterator::first()
+{
+ currentPos = 0;
+ return currentPos;
+}
+
+int LineBreakIterator::next()
+{
+ if (currentPos == length) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos < length) {
+ if (haveSpace && !isLineStop(string[currentPos]))
+ break;
+ if (isLineStop(string[currentPos]))
+ haveSpace = true;
+ ++currentPos;
+ }
+ return currentPos;
+}
+
+int LineBreakIterator::previous()
+{
+ if (!currentPos) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos > 0) {
+ if (haveSpace && !isLineStop(string[currentPos]))
+ break;
+ if (isLineStop(string[currentPos]))
+ haveSpace = true;
+ --currentPos;
+ }
+ return currentPos;
+}
+
+int SentenceBreakIterator::first()
+{
+ currentPos = 0;
+ return currentPos;
+}
+
+int SentenceBreakIterator::next()
+{
+ if (currentPos == length) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos < length) {
+ if (haveSpace && !isSentenceStop(string[currentPos]))
+ break;
+ if (isSentenceStop(string[currentPos]))
+ haveSpace = true;
+ ++currentPos;
+ }
+ return currentPos;
+}
+
+int SentenceBreakIterator::previous()
+{
+ if (!currentPos) {
+ currentPos = -1;
+ return currentPos;
+ }
+ bool haveSpace = false;
+ while (currentPos > 0) {
+ if (haveSpace && !isSentenceStop(string[currentPos]))
+ break;
+ if (isSentenceStop(string[currentPos]))
+ haveSpace = true;
+ --currentPos;
+ }
+ return currentPos;
+}
+
+TextBreakIterator* wordBreakIterator(const UChar* string, int length)
+{
+ DEFINE_STATIC_LOCAL(WordBreakIterator, iterator, ());
+ iterator.reset(string, length);
+ return &iterator;
+}
+
+TextBreakIterator* characterBreakIterator(const UChar* string, int length)
+{
+ DEFINE_STATIC_LOCAL(CharBreakIterator, iterator, ());
+ iterator.reset(string, length);
+ return &iterator;
+}
+
+TextBreakIterator* lineBreakIterator(const UChar* string, int length)
+{
+ DEFINE_STATIC_LOCAL(LineBreakIterator , iterator, ());
+ iterator.reset(string, length);
+ return &iterator;
+}
+
+TextBreakIterator* sentenceBreakIterator(const UChar* string, int length)
+{
+ DEFINE_STATIC_LOCAL(SentenceBreakIterator, iterator, ());
+ iterator.reset(string, length);
+ return &iterator;
+}
+
+int textBreakFirst(TextBreakIterator* breakIterator)
+{
+ return breakIterator->first();
+}
+
+int textBreakNext(TextBreakIterator* breakIterator)
+{
+ return breakIterator->next();
+}
+
+int textBreakPreceding(TextBreakIterator* breakIterator, int position)
+{
+ return breakIterator->preceding(position);
+}
+
+int textBreakFollowing(TextBreakIterator* breakIterator, int position)
+{
+ return breakIterator->following(position);
+}
+
+int textBreakCurrent(TextBreakIterator* breakIterator)
+{
+ return breakIterator->currentPos;
+}
+
+bool isTextBreak(TextBreakIterator*, int)
+{
+ return true;
+}
+
+TextBreakIterator* cursorMovementIterator(const UChar* string, int length)
+{
+ return characterBreakIterator(string, length);
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/brew/TextCodecBrew.cpp b/WebCore/platform/text/brew/TextCodecBrew.cpp
new file mode 100644
index 0000000..1f32298
--- /dev/null
+++ b/WebCore/platform/text/brew/TextCodecBrew.cpp
@@ -0,0 +1,214 @@
+/*
+ * Copyright (C) 2010 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "TextCodecBrew.h"
+
+#include "AEEAppGen.h"
+#include "AEEICharsetConv.h"
+#include "NotImplemented.h"
+#include "PlatformString.h"
+#include <wtf/Assertions.h>
+#include <wtf/text/CString.h>
+
+namespace WebCore {
+
+// FIXME: Not sure if there are Brew MP devices which use big endian.
+const char* WebCore::TextCodecBrew::m_internalEncodingName = "UTF-16LE";
+
+static PassOwnPtr<TextCodec> newTextCodecBrew(const TextEncoding& encoding, const void*)
+{
+ return new TextCodecBrew(encoding);
+}
+
+void TextCodecBrew::registerBaseEncodingNames(EncodingNameRegistrar registrar)
+{
+ registrar("UTF-8", "UTF-8");
+}
+
+void TextCodecBrew::registerBaseCodecs(TextCodecRegistrar registrar)
+{
+ registrar("UTF-8", newTextCodecBrew, 0);
+}
+
+void TextCodecBrew::registerExtendedEncodingNames(EncodingNameRegistrar registrar)
+{
+ // FIXME: Not sure how to enumerate all available encodings.
+ notImplemented();
+}
+
+void TextCodecBrew::registerExtendedCodecs(TextCodecRegistrar registrar)
+{
+ notImplemented();
+}
+
+TextCodecBrew::TextCodecBrew(const TextEncoding& encoding)
+ : m_charsetConverter(0)
+ , m_encoding(encoding)
+ , m_numBufferedBytes(0)
+{
+ String format = String::format("%s>%s", encoding.name(), m_internalEncodingName);
+
+ IShell* shell = reinterpret_cast<AEEApplet*>(GETAPPINSTANCE())->m_pIShell;
+ AEECLSID classID = ISHELL_GetHandler(shell, AEEIID_ICharsetConv, format.latin1().data());
+ ISHELL_CreateInstance(shell, classID, reinterpret_cast<void**>(&m_charsetConverter));
+
+ ASSERT(m_charsetConverter);
+}
+
+TextCodecBrew::~TextCodecBrew()
+{
+ if (m_charsetConverter)
+ ICharsetConv_Release(m_charsetConverter);
+}
+
+String TextCodecBrew::decode(const char* bytes, size_t length, bool flush, bool stopOnError, bool& sawError)
+{
+ int code = ICharsetConv_Initialize(m_charsetConverter, m_encoding.name(), m_internalEncodingName, 0);
+ ASSERT(code == AEE_SUCCESS);
+
+ Vector<UChar> result;
+ Vector<unsigned char> prefixedBytes(length);
+
+ int srcSize;
+ unsigned char* srcBegin;
+
+ if (m_numBufferedBytes) {
+ srcSize = length + m_numBufferedBytes;
+ prefixedBytes.grow(srcSize);
+ memcpy(prefixedBytes.data(), m_bufferedBytes, m_numBufferedBytes);
+ memcpy(prefixedBytes.data() + m_numBufferedBytes, bytes, length);
+
+ srcBegin = prefixedBytes.data();
+
+ // all buffered bytes are consumed now
+ m_numBufferedBytes = 0;
+ } else {
+ srcSize = length;
+ srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(bytes));
+ }
+
+ unsigned char* src = srcBegin;
+ unsigned char* srcEnd = srcBegin + srcSize;
+
+ Vector<UChar> dstBuffer(srcSize);
+
+ while (src < srcEnd) {
+ int numCharsConverted;
+ unsigned char* dstBegin = reinterpret_cast<unsigned char*>(dstBuffer.data());
+ unsigned char* dst = dstBegin;
+ int dstSize = dstBuffer.size() * sizeof(UChar);
+
+ code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
+ ASSERT(code != AEE_ENOSUCH);
+
+ if (code == AEE_EBUFFERTOOSMALL) {
+ // Increase the buffer and try it again.
+ dstBuffer.grow(dstBuffer.size() * 2);
+ continue;
+ }
+
+ if (code == AEE_EBADITEM) {
+ sawError = true;
+ if (stopOnError) {
+ result.append(L'?');
+ break;
+ }
+
+ src++;
+ }
+
+ if (code == AEE_EINCOMPLETEITEM) {
+ if (flush) {
+ LOG_ERROR("Partial bytes at end of input while flush requested.");
+ sawError = true;
+ return String();
+ }
+
+ m_numBufferedBytes = srcEnd - src;
+ memcpy(m_bufferedBytes, src, m_numBufferedBytes);
+ break;
+ }
+
+ int numChars = (dst - dstBegin) / sizeof(UChar);
+ if (numChars > 0)
+ result.append(dstBuffer.data(), numChars);
+ }
+
+ return String::adopt(result);
+}
+
+CString TextCodecBrew::encode(const UChar* characters, size_t length, UnencodableHandling handling)
+{
+ if (!length)
+ return "";
+
+ unsigned int replacementCharacter = '?';
+
+ // FIXME: Impossible to handle EntitiesForUnencodables or URLEncodedEntitiesForUnencodables with ICharsetConv.
+ int code = ICharsetConv_Initialize(m_charsetConverter, m_internalEncodingName, m_encoding.name(), replacementCharacter);
+ ASSERT(code == AEE_SUCCESS);
+
+ Vector<char> result;
+
+ int srcSize = length * sizeof(UChar);
+ unsigned char* srcBegin = const_cast<unsigned char*>(reinterpret_cast<const unsigned char*>(characters));
+ unsigned char* src = srcBegin;
+ unsigned char* srcEnd = srcBegin + srcSize;
+
+ Vector<unsigned char> dstBuffer(length * sizeof(UChar));
+
+ while (src < srcEnd) {
+ int numCharsConverted;
+ unsigned char* dstBegin = dstBuffer.data();
+ unsigned char* dst = dstBegin;
+ int dstSize = dstBuffer.size();
+
+ code = ICharsetConv_CharsetConvert(m_charsetConverter, &src, &srcSize, &dst, &dstSize, &numCharsConverted);
+ ASSERT(code != AEE_EINCOMPLETEITEM);
+
+ if (code == AEE_ENOSUCH) {
+ LOG_ERROR("Conversion error, Code=%d", code);
+ return CString();
+ }
+
+ if (code == AEE_EBUFFERTOOSMALL) {
+ // Increase the buffer and try it again.
+ dstBuffer.grow(dstBuffer.size() * 2);
+ continue;
+ }
+
+ if (code == AEE_EBADITEM)
+ src += sizeof(UChar); // Skip the invalid character
+
+ int numBytes = dst - dstBegin;
+ if (numBytes > 0)
+ result.append(dstBuffer.data(), numBytes);
+ }
+
+ return CString(result.data(), result.size());
+}
+
+} // namespace WebCore
diff --git a/WebCore/platform/text/brew/TextCodecBrew.h b/WebCore/platform/text/brew/TextCodecBrew.h
new file mode 100644
index 0000000..97e2c87
--- /dev/null
+++ b/WebCore/platform/text/brew/TextCodecBrew.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (C) 2010 Company 100, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef TextCodecBrew_h
+#define TextCodecBrew_h
+
+#include "TextCodec.h"
+#include "TextEncoding.h"
+
+typedef struct ICharsetConv ICharsetConv;
+
+namespace WebCore {
+
+class TextCodecBrew : public TextCodec {
+public:
+ static void registerBaseEncodingNames(EncodingNameRegistrar);
+ static void registerBaseCodecs(TextCodecRegistrar);
+
+ static void registerExtendedEncodingNames(EncodingNameRegistrar);
+ static void registerExtendedCodecs(TextCodecRegistrar);
+
+ TextCodecBrew(const TextEncoding&);
+ virtual ~TextCodecBrew();
+
+ virtual String decode(const char*, size_t length, bool flush, bool stopOnError, bool& sawError);
+ virtual CString encode(const UChar*, size_t length, UnencodableHandling);
+
+private:
+ TextEncoding m_encoding;
+ size_t m_numBufferedBytes;
+ unsigned char m_bufferedBytes[16]; // bigger than any single multi-byte character
+ ICharsetConv* m_charsetConverter;
+
+ static const char* m_internalEncodingName;
+};
+
+} // namespace WebCore
+
+#endif // TextCodecBrew_h
diff --git a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp
index dda443f..b9f5a9e 100644
--- a/WebCore/platform/text/qt/TextBreakIteratorQt.cpp
+++ b/WebCore/platform/text/qt/TextBreakIteratorQt.cpp
@@ -33,6 +33,12 @@
namespace WebCore {
+#if USE(QT_ICU_TEXT_BREAKING)
+const char* currentTextBreakLocaleID()
+{
+ return QLocale::system().name().toLatin1();
+}
+#else
static unsigned char buffer[1024];
class TextBreakIterator : public QTextBoundaryFinder {
@@ -135,5 +141,6 @@ namespace WebCore {
{
return true;
}
+#endif
}
diff --git a/WebCore/platform/text/wince/TextCodecWinCE.cpp b/WebCore/platform/text/wince/TextCodecWinCE.cpp
index 499035f..da6d5a5 100644
--- a/WebCore/platform/text/wince/TextCodecWinCE.cpp
+++ b/WebCore/platform/text/wince/TextCodecWinCE.cpp
@@ -33,6 +33,7 @@
#include <wtf/HashMap.h>
#include <wtf/HashSet.h>
#include <wtf/text/CString.h>
+#include <wtf/text/StringConcatenate.h>
#include <wtf/text/StringHash.h>
#include <wtf/unicode/UTF8.h>
@@ -110,7 +111,7 @@ LanguageManager::LanguageManager()
info.m_aliases.append(name);
info.m_aliases.append(String(cpInfo.wszHeaderCharset).latin1());
info.m_aliases.append(String(cpInfo.wszBodyCharset).latin1());
- String cpName = String::format("cp%d", cpInfo.uiCodePage);
+ String cpName = makeString("cp", String::number(cpInfo.uiCodePage));
info.m_aliases.append(cpName.latin1());
supportedCharsets().add(i->second.data());
}