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

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

Issue 1472083005: Remove kint64min. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@kint5
Patch Set: rebase Created 5 years 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
« no previous file with comments | « base/basictypes.h ('k') | base/strings/string_number_conversions_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) 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 <stdint.h>
8
7 #include <cmath> 9 #include <cmath>
10 #include <limits>
8 11
9 #include "base/json/string_escape.h" 12 #include "base/json/string_escape.h"
10 #include "base/logging.h" 13 #include "base/logging.h"
11 #include "base/strings/string_number_conversions.h" 14 #include "base/strings/string_number_conversions.h"
12 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
13 #include "base/values.h" 16 #include "base/values.h"
14 17
15 namespace base { 18 namespace base {
16 19
17 #if defined(OS_WIN) 20 #if defined(OS_WIN)
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 DCHECK(result); 75 DCHECK(result);
73 json_string_->append(IntToString(value)); 76 json_string_->append(IntToString(value));
74 return result; 77 return result;
75 } 78 }
76 79
77 case Value::TYPE_DOUBLE: { 80 case Value::TYPE_DOUBLE: {
78 double value; 81 double value;
79 bool result = node.GetAsDouble(&value); 82 bool result = node.GetAsDouble(&value);
80 DCHECK(result); 83 DCHECK(result);
81 if (omit_double_type_preservation_ && 84 if (omit_double_type_preservation_ &&
82 value <= kint64max && 85 value <= std::numeric_limits<int64_t>::max() &&
83 value >= kint64min && 86 value >= std::numeric_limits<int64_t>::min() &&
84 std::floor(value) == value) { 87 std::floor(value) == value) {
85 json_string_->append(Int64ToString(static_cast<int64>(value))); 88 json_string_->append(Int64ToString(static_cast<int64_t>(value)));
86 return result; 89 return result;
87 } 90 }
88 std::string real = DoubleToString(value); 91 std::string real = DoubleToString(value);
89 // Ensure that the number has a .0 if there's no decimal or 'e'. This 92 // Ensure that the number has a .0 if there's no decimal or 'e'. This
90 // makes sure that when we read the JSON back, it's interpreted as a 93 // makes sure that when we read the JSON back, it's interpreted as a
91 // real rather than an int. 94 // real rather than an int.
92 if (real.find('.') == std::string::npos && 95 if (real.find('.') == std::string::npos &&
93 real.find('e') == std::string::npos && 96 real.find('e') == std::string::npos &&
94 real.find('E') == std::string::npos) { 97 real.find('E') == std::string::npos) {
95 real.append(".0"); 98 real.append(".0");
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 } 202 }
200 NOTREACHED(); 203 NOTREACHED();
201 return false; 204 return false;
202 } 205 }
203 206
204 void JSONWriter::IndentLine(size_t depth) { 207 void JSONWriter::IndentLine(size_t depth) {
205 json_string_->append(depth * 3U, ' '); 208 json_string_->append(depth * 3U, ' ');
206 } 209 }
207 210
208 } // namespace base 211 } // namespace base
OLDNEW
« no previous file with comments | « base/basictypes.h ('k') | base/strings/string_number_conversions_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698