OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/basictypes.h" |
| 8 #include "base/format_macros.h" |
7 #include "base/json/string_escape.h" | 9 #include "base/json/string_escape.h" |
8 #include "base/logging.h" | 10 #include "base/logging.h" |
9 #include "base/stringprintf.h" | 11 #include "base/stringprintf.h" |
10 #include "base/string_number_conversions.h" | 12 #include "base/string_number_conversions.h" |
11 #include "base/values.h" | 13 #include "base/values.h" |
12 #include "base/utf_string_conversions.h" | 14 #include "base/utf_string_conversions.h" |
13 | 15 |
14 namespace base { | 16 namespace base { |
15 | 17 |
16 #if defined(OS_WIN) | 18 #if defined(OS_WIN) |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 | 73 |
72 case Value::TYPE_INTEGER: | 74 case Value::TYPE_INTEGER: |
73 { | 75 { |
74 int value; | 76 int value; |
75 bool result = node->GetAsInteger(&value); | 77 bool result = node->GetAsInteger(&value); |
76 DCHECK(result); | 78 DCHECK(result); |
77 base::StringAppendF(json_string_, "%d", value); | 79 base::StringAppendF(json_string_, "%d", value); |
78 break; | 80 break; |
79 } | 81 } |
80 | 82 |
| 83 case Value::TYPE_INTEGER64: |
| 84 { |
| 85 int64 value; |
| 86 bool result = node->GetAsInteger64(&value); |
| 87 DCHECK(result); |
| 88 base::StringAppendF(json_string_, "%" PRId64, value); |
| 89 break; |
| 90 } |
| 91 |
81 case Value::TYPE_DOUBLE: | 92 case Value::TYPE_DOUBLE: |
82 { | 93 { |
83 double value; | 94 double value; |
84 bool result = node->GetAsDouble(&value); | 95 bool result = node->GetAsDouble(&value); |
85 DCHECK(result); | 96 DCHECK(result); |
86 std::string real = DoubleToString(value); | 97 std::string real = DoubleToString(value); |
87 // Ensure that the number has a .0 if there's no decimal or 'e'. This | 98 // Ensure that the number has a .0 if there's no decimal or 'e'. This |
88 // makes sure that when we read the JSON back, it's interpreted as a | 99 // makes sure that when we read the JSON back, it's interpreted as a |
89 // real rather than an int. | 100 // real rather than an int. |
90 if (real.find('.') == std::string::npos && | 101 if (real.find('.') == std::string::npos && |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
213 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); | 224 JsonDoubleQuote(UTF8ToUTF16(str), true, json_string_); |
214 } | 225 } |
215 | 226 |
216 void JSONWriter::IndentLine(int depth) { | 227 void JSONWriter::IndentLine(int depth) { |
217 // It may be faster to keep an indent string so we don't have to keep | 228 // It may be faster to keep an indent string so we don't have to keep |
218 // reallocating. | 229 // reallocating. |
219 json_string_->append(std::string(depth * 3, ' ')); | 230 json_string_->append(std::string(depth * 3, ' ')); |
220 } | 231 } |
221 | 232 |
222 } // namespace base | 233 } // namespace base |
OLD | NEW |