Chromium Code Reviews| Index: src/debug-agent.cc |
| =================================================================== |
| --- src/debug-agent.cc (revision 10944) |
| +++ src/debug-agent.cc (working copy) |
| @@ -372,8 +372,11 @@ |
| // Calculate the message size in UTF-8 encoding. |
| int utf8_len = 0; |
| + int previous = unibrow::Utf8::kNoPreviousCharacter; |
| for (int i = 0; i < message.length(); i++) { |
| - utf8_len += unibrow::Utf8::Length(message[i]); |
| + uint16_t character = message[i]; |
| + utf8_len += unibrow::Utf8::Length(character, previous); |
| + previous = character; |
| } |
| // Send the header. |
| @@ -388,17 +391,30 @@ |
| // Send message body as UTF-8. |
| int buffer_position = 0; // Current buffer position. |
| + previous = unibrow::Utf8::kNoPreviousCharacter; |
| for (int i = 0; i < message.length(); i++) { |
| // Write next UTF-8 encoded character to buffer. |
| + uint16_t character = message[i]; |
| buffer_position += |
| - unibrow::Utf8::Encode(buffer + buffer_position, message[i]); |
| + unibrow::Utf8::Encode(buffer + buffer_position, character, previous); |
| ASSERT(buffer_position < kBufferSize); |
| // Send buffer if full or last character is encoded. |
| if (kBufferSize - buffer_position < 3 || i == message.length() - 1) { |
| - conn->Send(buffer, buffer_position); |
| - buffer_position = 0; |
| + if (unibrow::Utf16::IsLeadSurrogate(character)) { |
| + int kEncodedSurrogateLength = 3; |
|
rossberg
2012/03/07 13:32:47
Maybe move this declaration up and use it instead
Erik Corry
2012/03/11 19:29:22
The 3 above is actually a different 3. I gave the
|
| + ASSERT(buffer_position >= kEncodedSurrogateLength); |
| + conn->Send(buffer, buffer_position - kEncodedSurrogateLength); |
| + for (int i = 0; i < kEncodedSurrogateLength; i++) { |
| + buffer[i] = buffer[buffer_position + i]; |
| + } |
| + buffer_position = kEncodedSurrogateLength; |
| + } else { |
| + conn->Send(buffer, buffer_position); |
| + buffer_position = 0; |
| + } |
| } |
| + previous = character; |
| } |
| return true; |