| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "base/json/string_escape.h" | 7 #include "base/json/string_escape.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "base/string_util.h" | 9 #include "base/string_util.h" |
| 10 #include "base/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 68 | 68 |
| 69 case Value::TYPE_INTEGER: | 69 case Value::TYPE_INTEGER: |
| 70 { | 70 { |
| 71 int value; | 71 int value; |
| 72 bool result = node->GetAsInteger(&value); | 72 bool result = node->GetAsInteger(&value); |
| 73 DCHECK(result); | 73 DCHECK(result); |
| 74 StringAppendF(json_string_, "%d", value); | 74 StringAppendF(json_string_, "%d", value); |
| 75 break; | 75 break; |
| 76 } | 76 } |
| 77 | 77 |
| 78 case Value::TYPE_REAL: | 78 case Value::TYPE_DOUBLE: |
| 79 { | 79 { |
| 80 double value; | 80 double value; |
| 81 bool result = node->GetAsReal(&value); | 81 bool result = node->GetAsDouble(&value); |
| 82 DCHECK(result); | 82 DCHECK(result); |
| 83 std::string real = DoubleToString(value); | 83 std::string real = DoubleToString(value); |
| 84 // Ensure that the number has a .0 if there's no decimal or 'e'. This | 84 // Ensure that the number has a .0 if there's no decimal or 'e'. This |
| 85 // makes sure that when we read the JSON back, it's interpreted as a | 85 // makes sure that when we read the JSON back, it's interpreted as a |
| 86 // real rather than an int. | 86 // real rather than an int. |
| 87 if (real.find('.') == std::string::npos && | 87 if (real.find('.') == std::string::npos && |
| 88 real.find('e') == std::string::npos && | 88 real.find('e') == std::string::npos && |
| 89 real.find('E') == std::string::npos) { | 89 real.find('E') == std::string::npos) { |
| 90 real.append(".0"); | 90 real.append(".0"); |
| 91 } | 91 } |
| (...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 194 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); | 194 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); |
| 195 } | 195 } |
| 196 | 196 |
| 197 void JSONWriter::IndentLine(int depth) { | 197 void JSONWriter::IndentLine(int depth) { |
| 198 // It may be faster to keep an indent string so we don't have to keep | 198 // It may be faster to keep an indent string so we don't have to keep |
| 199 // reallocating. | 199 // reallocating. |
| 200 json_string_->append(std::string(depth * 3, ' ')); | 200 json_string_->append(std::string(depth * 3, ' ')); |
| 201 } | 201 } |
| 202 | 202 |
| 203 } // namespace base | 203 } // namespace base |
| OLD | NEW |