OLD | NEW |
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_writer.h" | 5 #include "base/json/json_writer.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 { | 166 { |
167 json_string_->append("{"); | 167 json_string_->append("{"); |
168 if (pretty_print_) | 168 if (pretty_print_) |
169 json_string_->append(kPrettyPrintLineEnding); | 169 json_string_->append(kPrettyPrintLineEnding); |
170 | 170 |
171 const DictionaryValue* dict = | 171 const DictionaryValue* dict = |
172 static_cast<const DictionaryValue*>(node); | 172 static_cast<const DictionaryValue*>(node); |
173 for (DictionaryValue::key_iterator key_itr = dict->begin_keys(); | 173 for (DictionaryValue::key_iterator key_itr = dict->begin_keys(); |
174 key_itr != dict->end_keys(); | 174 key_itr != dict->end_keys(); |
175 ++key_itr) { | 175 ++key_itr) { |
176 Value* value = NULL; | 176 const Value* value = NULL; |
177 bool result = dict->GetWithoutPathExpansion(*key_itr, &value); | 177 bool result = dict->GetWithoutPathExpansion(*key_itr, &value); |
178 DCHECK(result); | 178 DCHECK(result); |
179 | 179 |
180 if (omit_binary_values_ && value->GetType() == Value::TYPE_BINARY) { | 180 if (omit_binary_values_ && value->GetType() == Value::TYPE_BINARY) { |
181 continue; | 181 continue; |
182 } | 182 } |
183 | 183 |
184 if (key_itr != dict->begin_keys()) { | 184 if (key_itr != dict->begin_keys()) { |
185 json_string_->append(","); | 185 json_string_->append(","); |
186 if (pretty_print_) | 186 if (pretty_print_) |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
227 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); | 227 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); |
228 } | 228 } |
229 | 229 |
230 void JSONWriter::IndentLine(int depth) { | 230 void JSONWriter::IndentLine(int depth) { |
231 // It may be faster to keep an indent string so we don't have to keep | 231 // It may be faster to keep an indent string so we don't have to keep |
232 // reallocating. | 232 // reallocating. |
233 json_string_->append(std::string(depth * 3, ' ')); | 233 json_string_->append(std::string(depth * 3, ' ')); |
234 } | 234 } |
235 | 235 |
236 } // namespace base | 236 } // namespace base |
OLD | NEW |