From 1fa3bf0f07a0875fb1d0cc2a70df5bdaaaf8069e Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Fri, 3 Oct 2014 14:30:19 -0700 Subject: [PATCH] In SpyReader::read, always return complete unicode characters --- spec/runtime/helpers/spy_reader.cc | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spec/runtime/helpers/spy_reader.cc b/spec/runtime/helpers/spy_reader.cc index 621685f7..8d07754c 100644 --- a/spec/runtime/helpers/spy_reader.cc +++ b/spec/runtime/helpers/spy_reader.cc @@ -43,12 +43,17 @@ SpyReader::~SpyReader() { } const char * SpyReader::read(size_t *bytes_read) { - string result = content.substr(position, chunk_size); - position += result.size(); - strings_read.back() += result; - *bytes_read = result.size(); + const char *start = content.data() + position; + long len = position_for_char_index(start, content.size() - position, chunk_size); + if (len < 0) + len = content.size() - position; + + *bytes_read = len; + position += len; + strings_read.back() += string(start, len); + memset(buffer, 0, chunk_size); - memcpy(buffer, result.data(), result.size()); + memcpy(buffer, start, len); return buffer; }