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

Side by Side Diff: base/json/json_string_value_serializer.cc

Issue 9590002: JSONWriter cleanup: integrate pretty print into write options. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix merge conflict 7. Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | base/json/json_writer.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/json/json_string_value_serializer.h" 5 #include "base/json/json_string_value_serializer.h"
6 6
7 #include "base/json/json_reader.h" 7 #include "base/json/json_reader.h"
8 #include "base/json/json_writer.h" 8 #include "base/json/json_writer.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 10
11 JSONStringValueSerializer::~JSONStringValueSerializer() {} 11 JSONStringValueSerializer::~JSONStringValueSerializer() {}
12 12
13 bool JSONStringValueSerializer::Serialize(const Value& root) { 13 bool JSONStringValueSerializer::Serialize(const Value& root) {
14 return SerializeInternal(root, false); 14 return SerializeInternal(root, false);
15 } 15 }
16 16
17 bool JSONStringValueSerializer::SerializeAndOmitBinaryValues( 17 bool JSONStringValueSerializer::SerializeAndOmitBinaryValues(
18 const Value& root) { 18 const Value& root) {
19 return SerializeInternal(root, true); 19 return SerializeInternal(root, true);
20 } 20 }
21 21
22 bool JSONStringValueSerializer::SerializeInternal(const Value& root, 22 bool JSONStringValueSerializer::SerializeInternal(const Value& root,
23 bool omit_binary_values) { 23 bool omit_binary_values) {
24 if (!json_string_ || initialized_with_const_string_) 24 if (!json_string_ || initialized_with_const_string_)
25 return false; 25 return false;
26 26
27 base::JSONWriter::WriteWithOptions( 27 int options = 0;
28 &root, 28 if (omit_binary_values)
29 pretty_print_, 29 options |= base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES;
30 omit_binary_values ? base::JSONWriter::OPTIONS_OMIT_BINARY_VALUES : 0, 30 if (pretty_print_)
31 json_string_); 31 options |= base::JSONWriter::OPTIONS_PRETTY_PRINT;
32
33 base::JSONWriter::WriteWithOptions(&root, options, json_string_);
32 return true; 34 return true;
33 } 35 }
34 36
35 Value* JSONStringValueSerializer::Deserialize(int* error_code, 37 Value* JSONStringValueSerializer::Deserialize(int* error_code,
36 std::string* error_str) { 38 std::string* error_str) {
37 if (!json_string_) 39 if (!json_string_)
38 return NULL; 40 return NULL;
39 41
40 return base::JSONReader::ReadAndReturnError(*json_string_, 42 return base::JSONReader::ReadAndReturnError(*json_string_,
41 allow_trailing_comma_, 43 allow_trailing_comma_,
42 error_code, 44 error_code,
43 error_str); 45 error_str);
44 } 46 }
45
OLDNEW
« no previous file with comments | « no previous file | base/json/json_writer.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698