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

Side by Side Diff: base/json_writer.cc

Issue 11423: Remove the locale parameter from the StringToDouble and (Closed)
Patch Set: more comments Created 12 years, 1 month 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/json_reader_unittest.cc ('k') | base/string_util.h » ('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"
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
51 DCHECK(result); 51 DCHECK(result);
52 StringAppendF(json_string_, "%d", value); 52 StringAppendF(json_string_, "%d", value);
53 break; 53 break;
54 } 54 }
55 55
56 case Value::TYPE_REAL: 56 case Value::TYPE_REAL:
57 { 57 {
58 double value; 58 double value;
59 bool result = node->GetAsReal(&value); 59 bool result = node->GetAsReal(&value);
60 DCHECK(result); 60 DCHECK(result);
61 std::string real = base::DoubleToString(value, base::LOCALE_INDEPENDENT) ; 61 std::string real = DoubleToString(value);
62 // Ensure that the number has a .0 if there's no decimal or 'e'. This 62 // Ensure that the number has a .0 if there's no decimal or 'e'. This
63 // makes sure that when we read the JSON back, it's interpreted as a 63 // makes sure that when we read the JSON back, it's interpreted as a
64 // real rather than an int. 64 // real rather than an int.
65 if (real.find('.') == std::string::npos && 65 if (real.find('.') == std::string::npos &&
66 real.find('e') == std::string::npos && 66 real.find('e') == std::string::npos &&
67 real.find('E') == std::string::npos) { 67 real.find('E') == std::string::npos) {
68 real.append(".0"); 68 real.append(".0");
69 } 69 }
70 json_string_->append(real); 70 json_string_->append(real);
71 break; 71 break;
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
158 void JSONWriter::AppendQuotedString(const std::wstring& str) { 158 void JSONWriter::AppendQuotedString(const std::wstring& str) {
159 string_escape::JavascriptDoubleQuote(str, true, json_string_); 159 string_escape::JavascriptDoubleQuote(str, true, json_string_);
160 } 160 }
161 161
162 void JSONWriter::IndentLine(int depth) { 162 void JSONWriter::IndentLine(int depth) {
163 // It may be faster to keep an indent string so we don't have to keep 163 // It may be faster to keep an indent string so we don't have to keep
164 // reallocating. 164 // reallocating.
165 json_string_->append(std::string(depth * 3, ' ')); 165 json_string_->append(std::string(depth * 3, ' '));
166 } 166 }
167 167
OLDNEW
« no previous file with comments | « base/json_reader_unittest.cc ('k') | base/string_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698