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

Side by Side Diff: base/json_writer.cc

Issue 147220: Use platform-appropriate newlines in JSON output (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 11 years, 6 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 | « base/json_reader_unittest.cc ('k') | base/json_writer_unittest.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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_writer.h" 5 #include "base/json_writer.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "base/values.h" 9 #include "base/values.h"
10 #include "base/string_escape.h" 10 #include "base/string_escape.h"
11 11
12 const char kPrettyPrintLineEnding[] = "\r\n"; 12 #if defined(OS_WIN)
13 static const char kPrettyPrintLineEnding[] = "\r\n";
14 #else
15 static const char kPrettyPrintLineEnding[] = "\n";
16 #endif
13 17
14 /* static */ 18 /* static */
15 void JSONWriter::Write(const Value* const node, 19 void JSONWriter::Write(const Value* const node,
16 bool pretty_print, 20 bool pretty_print,
17 std::string* json) { 21 std::string* json) {
18 WriteWithOptionalEscape(node, pretty_print, true, json); 22 WriteWithOptionalEscape(node, pretty_print, true, json);
19 } 23 }
20 24
21 /* static */ 25 /* static */
22 void JSONWriter::WriteWithOptionalEscape(const Value* const node, 26 void JSONWriter::WriteWithOptionalEscape(const Value* const node,
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after
184 string_escape::JsonDoubleQuote(WideToUTF16Hack(str), 188 string_escape::JsonDoubleQuote(WideToUTF16Hack(str),
185 true, 189 true,
186 json_string_); 190 json_string_);
187 } 191 }
188 192
189 void JSONWriter::IndentLine(int depth) { 193 void JSONWriter::IndentLine(int depth) {
190 // It may be faster to keep an indent string so we don't have to keep 194 // It may be faster to keep an indent string so we don't have to keep
191 // reallocating. 195 // reallocating.
192 json_string_->append(std::string(depth * 3, ' ')); 196 json_string_->append(std::string(depth * 3, ' '));
193 } 197 }
OLDNEW
« no previous file with comments | « base/json_reader_unittest.cc ('k') | base/json_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698