[webkit-dev] Question about StringImpl::create

Gavin Barraclough barraclough at apple.com
Thu Dec 16 22:36:24 PST 2010

On Dec 16, 2010, at 9:45 PM, 谢愈挺 wrote:

> I have a question about "StringImpl::create()". Is it can only input latin1 data?

Yes, this method takes latin1 data all const char* arguments in WTFString are handled as latin1.
String::fromUTF8 can be used to create strings with utf8 data.

> If it can only input the latin1 data, the following code maybe incorrect:
> In WTFString.cpp :
> String String::format(const char *format, ...)
> {
>  ...
>     Vector<char, 256> buffer;
> ...
>   return StringImpl::create(buffer.data(), len);
> }
> The buffer.data() maybe utf8 data!

The short answer is that String::format should be considered deprecated - its behavior is platform-specific, and we'd like to move away from it.

Since all const char* arguments to the String methods are treated as latin1, format is not suitable for use with utf8 data – any code that is calling format but that may be working with utf8 data needs to be refactored to stop using this method (utf8 should be converted to WebCore Strings first, then use the other conversion/concatenation methods available).


> Thanks.
> pattin
> _______________________________________________
> webkit-dev mailing list
> webkit-dev at lists.webkit.org
> http://lists.webkit.org/mailman/listinfo.cgi/webkit-dev

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-dev/attachments/20101216/0a71c013/attachment.html>

More information about the webkit-dev mailing list