Commit 347c0326 authored by beidson@apple.com's avatar beidson@apple.com

JavaScriptCore:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin

        Export Unicode/UTF8.h and convertUTF16ToUTF8() for more flexible conversion in WebCore

        * JavaScriptCore.exp:
        * JavaScriptCore.xcodeproj/project.pbxproj:

WebCore:

2008-03-28  Brady Eidson  <beidson@apple.com>

        Reviewed by Darin

        Using convertUTF16ToUTF8() from WTF, add a helper function that gives you a UTF8 SharedBuffer
        created from a String.

        * ForwardingHeaders/wtf/unicode/UTF8.h: Added.
        * platform/text/PlatformString.h:
        * platform/text/String.cpp:
        (WebCore::utf8Buffer):



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@31398 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 3cd8ef7a
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin
Export Unicode/UTF8.h and convertUTF16ToUTF8() for more flexible conversion in WebCore
* JavaScriptCore.exp:
* JavaScriptCore.xcodeproj/project.pbxproj:
2008-03-27 Darin Adler <darin@apple.com>
Reviewed by Mark Rowe.
......
......@@ -217,6 +217,7 @@ __ZN3WTF5Mutex6unlockEv
__ZN3WTF5Mutex7tryLockEv
__ZN3WTF5MutexC1Ev
__ZN3WTF5MutexD1Ev
__ZN3WTF7Unicode18convertUTF16ToUTF8EPPKtS2_PPcS4_b
__ZN3WTF8Collator18setOrderLowerFirstEb
__ZN3WTF8CollatorC1EPKc
__ZN3WTF8CollatorD1Ev
......
......@@ -199,7 +199,7 @@
E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */; };
E1EE798C0D6CA53D00FEA3BA /* MessageQueue.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EE798B0D6CA53D00FEA3BA /* MessageQueue.h */; settings = {ATTRIBUTES = (Private, ); }; };
E1EF79AA0CE97BA60088D500 /* UTF8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EF79A80CE97BA60088D500 /* UTF8.cpp */; };
E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EF79A90CE97BA60088D500 /* UTF8.h */; };
E1EF79AB0CE97BA60088D500 /* UTF8.h in Headers */ = {isa = PBXBuildFile; fileRef = E1EF79A90CE97BA60088D500 /* UTF8.h */; settings = {ATTRIBUTES = (Private, ); }; };
/* End PBXBuildFile section */
/* Begin PBXBuildRule section */
......
2008-03-28 Brady Eidson <beidson@apple.com>
Reviewed by Darin
Using convertUTF16ToUTF8() from WTF, add a helper function that gives you a UTF8 SharedBuffer
created from a String.
* ForwardingHeaders/wtf/unicode/UTF8.h: Added.
* platform/text/PlatformString.h:
* platform/text/String.cpp:
(WebCore::utf8Buffer):
2008-03-28 Darin Adler <darin@apple.com>
Reviewed by Adam.
#include <JavaScriptCore/UTF8.h>
......@@ -43,6 +43,7 @@ class wxString;
namespace WebCore {
class CString;
class SharedBuffer;
struct StringHash;
class String {
......@@ -299,6 +300,8 @@ inline void append(Vector<UChar>& vector, const String& string)
vector.append(string.characters(), string.length());
}
PassRefPtr<SharedBuffer> utf8Buffer(const String&);
} // namespace WebCore
namespace WTF {
......
......@@ -33,11 +33,13 @@
#include <wtf/StringExtras.h>
#include <wtf/Vector.h>
#include <wtf/unicode/Unicode.h>
#include <wtf/unicode/UTF8.h>
using KJS::Identifier;
using KJS::UString;
using namespace WTF;
using namespace WTF::Unicode;
namespace WebCore {
......@@ -788,6 +790,23 @@ float charactersToFloat(const UChar* data, size_t length, bool* ok)
return narrowPrecisionToFloat(charactersToDouble(data, length, ok));
}
PassRefPtr<SharedBuffer> utf8Buffer(const String& string)
{
// Allocate a buffer big enough to hold all the characters.
const int length = string.length();
Vector<char> buffer(length * 3);
// Convert to runs of 8-bit characters.
char* p = buffer.data();
const UChar* d = string.characters();
ConversionResult result = convertUTF16ToUTF8(&d, d + length, &p, p + buffer.size(), true);
if (result != conversionOK)
return 0;
buffer.shrink(p - buffer.data());
return SharedBuffer::adoptVector(buffer);
}
} // namespace WebCore
#ifndef NDEBUG
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment