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

Unified Diff: base/json/json_writer.cc

Issue 1131113004: Convert JsonWriter::Write to taking a const ref for the in-param (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: another rebase Created 5 years, 7 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 | « base/json/json_writer.h ('k') | base/json/json_writer_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/json/json_writer.cc
diff --git a/base/json/json_writer.cc b/base/json/json_writer.cc
index d14c92c06e5a406d1c4a5b81d3764254ccaadc37..abfead80070d4354f878c6a8419f6e4a315d2e26 100644
--- a/base/json/json_writer.cc
+++ b/base/json/json_writer.cc
@@ -21,12 +21,13 @@ const char kPrettyPrintLineEnding[] = "\n";
#endif
// static
-bool JSONWriter::Write(const Value* const node, std::string* json) {
+bool JSONWriter::Write(const Value& node, std::string* json) {
return WriteWithOptions(node, 0, json);
}
// static
-bool JSONWriter::WriteWithOptions(const Value* const node, int options,
+bool JSONWriter::WriteWithOptions(const Value& node,
+ int options,
std::string* json) {
json->clear();
// Is there a better way to estimate the size of the output?
@@ -50,8 +51,8 @@ JSONWriter::JSONWriter(int options, std::string* json)
DCHECK(json);
}
-bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
- switch (node->GetType()) {
+bool JSONWriter::BuildJSONString(const Value& node, size_t depth) {
+ switch (node.GetType()) {
case Value::TYPE_NULL: {
json_string_->append("null");
return true;
@@ -59,7 +60,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
case Value::TYPE_BOOLEAN: {
bool value;
- bool result = node->GetAsBoolean(&value);
+ bool result = node.GetAsBoolean(&value);
DCHECK(result);
json_string_->append(value ? "true" : "false");
return result;
@@ -67,7 +68,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
case Value::TYPE_INTEGER: {
int value;
- bool result = node->GetAsInteger(&value);
+ bool result = node.GetAsInteger(&value);
DCHECK(result);
json_string_->append(IntToString(value));
return result;
@@ -75,7 +76,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
case Value::TYPE_DOUBLE: {
double value;
- bool result = node->GetAsDouble(&value);
+ bool result = node.GetAsDouble(&value);
DCHECK(result);
if (omit_double_type_preservation_ &&
value <= kint64max &&
@@ -107,7 +108,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
case Value::TYPE_STRING: {
std::string value;
- bool result = node->GetAsString(&value);
+ bool result = node.GetAsString(&value);
DCHECK(result);
EscapeJSONString(value, true, json_string_);
return result;
@@ -120,7 +121,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
const ListValue* list = NULL;
bool first_value_has_been_output = false;
- bool result = node->GetAsList(&list);
+ bool result = node.GetAsList(&list);
DCHECK(result);
for (ListValue::const_iterator it = list->begin(); it != list->end();
++it) {
@@ -134,7 +135,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
json_string_->push_back(' ');
}
- if (!BuildJSONString(value, depth))
+ if (!BuildJSONString(*value, depth))
result = false;
first_value_has_been_output = true;
@@ -153,7 +154,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
const DictionaryValue* dict = NULL;
bool first_value_has_been_output = false;
- bool result = node->GetAsDictionary(&dict);
+ bool result = node.GetAsDictionary(&dict);
DCHECK(result);
for (DictionaryValue::Iterator itr(*dict); !itr.IsAtEnd();
itr.Advance()) {
@@ -176,7 +177,7 @@ bool JSONWriter::BuildJSONString(const Value* const node, size_t depth) {
if (pretty_print_)
json_string_->push_back(' ');
- if (!BuildJSONString(&itr.value(), depth + 1U))
+ if (!BuildJSONString(itr.value(), depth + 1U))
result = false;
first_value_has_been_output = true;
« no previous file with comments | « base/json/json_writer.h ('k') | base/json/json_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698