String::WriteUtf8() problems.

25 views
Skip to first unread message

r...@tinyclouds.org

unread,
Apr 1, 2010, 3:29:02 PM4/1/10
to v8-users
String::WriteUtf8() does not provide enough information to write a
string to multiple buffers.

int WriteUtf8(char* buffer, int length = -1) const;

The documentation says the return value is the number of characters:

* \return The number of characters copied to the buffer
* excluding the NULL terminator.

but a quick look at the source code and tests reveal that WriteUtf8
actually returns the number of bytes written (correct me if I'm
wrong). I need to get a handle on where the writing terminated in
order to continue on the next buffer. As far as I can see this is
impossible with the current interface.

If this function returned the number of characters, I could then do

var rest = string.slice(charsWritten);

so getting the rest of the string is okay, but then I won't know how
many bytes were written in the original WriteUtf8. I couldn't assume
that `capacity` bytes were written because there might be a character
boundary...

Best would be if the function was changed to return both the bytes and
characters written:

int WriteUtf8(char* buffer, int length, int *charsWritten);

Would V8 accept a patch to change this?

r...@tinyclouds.org

unread,
Apr 1, 2010, 4:19:28 PM4/1/10
to v8-users
Reply all
Reply to author
Forward
0 new messages