Commit b9daa3e7 authored by jeffm@apple.com's avatar jeffm@apple.com

2011-04-07 Jeff Miller <jeffm@apple.com>

        Reviewed by Adam Roben.

        Replace WKStringGetCharactersPtr() with WKStringGetCharacters()
        https://bugs.webkit.org/show_bug.cgi?id=58058

        * TestWebKitAPI/Tests/WebKit2/WKString.cpp:
        (TestWebKitAPI::TEST): Add tests for  WKStringGetLength() and WKStringGetCharactersPtr().
2011-04-07  Jeff Miller  <jeffm@apple.com>

        Reviewed by Adam Roben.

        Replace WKStringGetCharactersPtr() with WKStringGetCharacters()
        https://bugs.webkit.org/show_bug.cgi?id=58058
        
        WKStringGetCharactersPtr() exposes the internal implementation of WKString, so change this to WKStringGetCharacters(), which makes a UTF-16 copy.

        * Shared/API/c/WKString.cpp:
        (WKStringGetCharacters): Added, replaces WKStringGetCharactersPtr().
        * Shared/API/c/WKString.h: Replaced WKStringGetCharactersPtr() with WKStringGetCharacters().
        * Shared/WebString.h:
        (WebKit::WebString::getCharacters): Added.


git-svn-id: svn://svn.chromium.org/blink/trunk@83198 bbb929c8-8fbe-4397-9dbb-9b2b20218538
parent df831400
2011-04-07 Jeff Miller <jeffm@apple.com>
Reviewed by Adam Roben.
Replace WKStringGetCharactersPtr() with WKStringGetCharacters()
https://bugs.webkit.org/show_bug.cgi?id=58058
WKStringGetCharactersPtr() exposes the internal implementation of WKString, so change this to WKStringGetCharacters(), which makes a UTF-16 copy.
* Shared/API/c/WKString.cpp:
(WKStringGetCharacters): Added, replaces WKStringGetCharactersPtr().
* Shared/API/c/WKString.h: Replaced WKStringGetCharactersPtr() with WKStringGetCharacters().
* Shared/WebString.h:
(WebKit::WebString::getCharacters): Added.
2011-04-07 Brian Weinstein <bweinstein@apple.com>
Reviewed by Adam Roben.
......
......@@ -52,10 +52,10 @@ size_t WKStringGetLength(WKStringRef stringRef)
return toImpl(stringRef)->length();
}
const WKChar* WKStringGetCharactersPtr(WKStringRef stringRef)
size_t WKStringGetCharacters(WKStringRef stringRef, WKChar* buffer, size_t bufferLength)
{
COMPILE_ASSERT(sizeof(WKChar) == sizeof(UChar), WKStringGetCharactersPtr_sizeof_WKChar_matches_UChar);
return reinterpret_cast<const WKChar*>(toImpl(stringRef)->characters());
COMPILE_ASSERT(sizeof(WKChar) == sizeof(UChar), WKStringGetCharacters_sizeof_WKChar_matches_UChar);
return (toImpl(stringRef)->getCharacters(static_cast<UChar*>(buffer), bufferLength));
}
size_t WKStringGetMaximumUTF8CStringSize(WKStringRef stringRef)
......
......@@ -50,7 +50,7 @@ WK_EXPORT WKStringRef WKStringCreateWithUTF8CString(const char* string);
WK_EXPORT bool WKStringIsEmpty(WKStringRef string);
WK_EXPORT size_t WKStringGetLength(WKStringRef string);
WK_EXPORT const WKChar* WKStringGetCharactersPtr(WKStringRef string);
WK_EXPORT size_t WKStringGetCharacters(WKStringRef string, WKChar* buffer, size_t bufferLength);
WK_EXPORT size_t WKStringGetMaximumUTF8CStringSize(WKStringRef string);
WK_EXPORT size_t WKStringGetUTF8CString(WKStringRef string, char* buffer, size_t bufferSize);
......
......@@ -59,7 +59,14 @@ public:
bool isEmpty() const { return m_string.isEmpty(); }
size_t length() const { return m_string.length(); }
const UChar* characters() const { return m_string.characters(); }
size_t getCharacters(UChar* buffer, size_t bufferLength) const
{
if (!bufferLength)
return 0;
bufferLength = std::min(bufferLength, m_string.length());
memcpy(buffer, m_string.characters(), bufferLength * sizeof(UChar));
return bufferLength;
}
size_t maximumUTF8CStringSize() const { return m_string.length() * 3 + 1; }
size_t getUTF8CString(char* buffer, size_t bufferSize)
......
2011-04-07 Jeff Miller <jeffm@apple.com>
Reviewed by Adam Roben.
Replace WKStringGetCharactersPtr() with WKStringGetCharacters()
https://bugs.webkit.org/show_bug.cgi?id=58058
* TestWebKitAPI/Tests/WebKit2/WKString.cpp:
(TestWebKitAPI::TEST): Add tests for WKStringGetLength() and WKStringGetCharactersPtr().
2011-04-07 Chang Shu <cshu@webkit.org>
Reviewed by Darin Adler.
......
......@@ -46,6 +46,27 @@ TEST(WebKit2, WKString)
delete[] buffer;
maxSize = WKStringGetLength(string);
TEST_ASSERT(maxSize == 5);
// Allocate a buffer one character larger than we need.
WKChar* uniBuffer = new WKChar[maxSize+1];
actualSize = WKStringGetCharacters(string, uniBuffer, maxSize);
TEST_ASSERT(actualSize == 5);
WKChar helloBuffer[] = { 'h', 'e', 'l', 'l', 'o' };
TEST_ASSERT(!memcmp(uniBuffer, helloBuffer, 10));
// Test passing a buffer length < the string length.
actualSize = WKStringGetCharacters(string, uniBuffer, maxSize-1);
TEST_ASSERT(actualSize == 4);
// Test passing a buffer length > the string length.
actualSize = WKStringGetCharacters(string, uniBuffer, maxSize+1);
TEST_ASSERT(actualSize == 5);
delete[] uniBuffer;
WKRelease(string);
}
......
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