Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Unified Diff: src/api.cc

Issue 1629001: Landing http://codereview.chromium.org/1539013 for ry@tinyclouds.org. (Closed)
Patch Set: Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 576b064559d210e72c3fde42a8e94d3fd1720dc0..0c1861f7fda4ba0d64703be8bc79e94f7c95d0d5 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -2641,7 +2641,7 @@ int String::Utf8Length() const {
}
-int String::WriteUtf8(char* buffer, int capacity) const {
+int String::WriteUtf8(char* buffer, int capacity, int* nchars_ref) const {
if (IsDeadCheck("v8::String::WriteUtf8()")) return 0;
LOG_API("String::WriteUtf8");
ENTER_V8;
@@ -2655,10 +2655,12 @@ int String::WriteUtf8(char* buffer, int capacity) const {
int fast_end = capacity - (unibrow::Utf8::kMaxEncodedSize - 1);
int i;
int pos = 0;
+ int nchars = 0;
for (i = 0; i < len && (capacity == -1 || pos < fast_end); i++) {
i::uc32 c = write_input_buffer.GetNext();
int written = unibrow::Utf8::Encode(buffer + pos, c);
pos += written;
+ nchars++;
}
if (i < len) {
// For the last characters we need to check the length for each one
@@ -2672,12 +2674,14 @@ int String::WriteUtf8(char* buffer, int capacity) const {
for (int j = 0; j < written; j++)
buffer[pos + j] = intermediate[j];
pos += written;
+ nchars++;
} else {
// We've reached the end of the buffer
break;
}
}
}
+ if (nchars_ref != NULL) *nchars_ref = nchars;
if (i == len && (capacity == -1 || pos < capacity))
buffer[pos++] = '\0';
return pos;
« no previous file with comments | « include/v8.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698