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

Unified Diff: runtime/vm/json_stream.cc

Issue 1653183002: getObject now supports specifying offset,count for strings. (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 4 years, 11 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 | « runtime/vm/json_stream.h ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: runtime/vm/json_stream.cc
diff --git a/runtime/vm/json_stream.cc b/runtime/vm/json_stream.cc
index 4851875703cd3b4c12c6e552b63d2a039c1169fc..4d2f27bea542c4c3ee6ef2dfabb4c5e83be3ce95 100644
--- a/runtime/vm/json_stream.cc
+++ b/runtime/vm/json_stream.cc
@@ -396,10 +396,12 @@ void JSONStream::PrintValue(const char* s) {
}
-bool JSONStream::PrintValueStr(const String& s, intptr_t limit) {
+bool JSONStream::PrintValueStr(const String& s,
+ intptr_t offset,
+ intptr_t count) {
PrintCommaIfNeeded();
buffer_.AddChar('"');
- bool did_truncate = AddDartString(s, limit);
+ bool did_truncate = AddDartString(s, offset, count);
buffer_.AddChar('"');
return did_truncate;
}
@@ -534,9 +536,10 @@ void JSONStream::PrintPropertyBase64(const char* name,
bool JSONStream::PrintPropertyStr(const char* name,
const String& s,
- intptr_t limit) {
+ intptr_t offset,
+ intptr_t count) {
PrintPropertyName(name);
- return PrintValueStr(s, limit);
+ return PrintValueStr(s, offset, count);
}
@@ -702,23 +705,24 @@ void JSONStream::AddEscapedUTF8String(const char* s, intptr_t len) {
}
-bool JSONStream::AddDartString(const String& s, intptr_t limit) {
- bool did_truncate = false;
+bool JSONStream::AddDartString(const String& s,
+ intptr_t offset,
+ intptr_t count) {
intptr_t length = s.Length();
- if (limit == -1) {
- limit = length;
+ ASSERT(offset >= 0);
+ if (offset > length) {
+ offset = length;
}
- if (length <= limit) {
- limit = length;
- } else {
- did_truncate = true;
+ if (!Utils::RangeCheck(offset, count, length)) {
+ count = length - offset;
}
-
- for (intptr_t i = 0; i < limit; i++) {
+ intptr_t limit = offset + count;
+ for (intptr_t i = offset; i < limit; i++) {
intptr_t code_unit = s.CharAt(i);
buffer_.EscapeAndAddCodeUnit(code_unit);
}
- return did_truncate;
+ // Return value indicates whether the string is truncated.
+ return (offset > 0) || (limit < length);
}
« no previous file with comments | « runtime/vm/json_stream.h ('k') | runtime/vm/json_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698