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

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

Issue 7649006: more changes (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix another typo Created 9 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « no previous file | base/json/json_writer_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) 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_reader.h" 5 #include "base/json/json_reader.h"
6 6
7 #include "base/float_util.h" 7 #include "base/float_util.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/stringprintf.h" 10 #include "base/stringprintf.h"
(...skipping 201 matching lines...) Expand 10 before | Expand all | Expand 10 after
212 } 212 }
213 213
214 scoped_ptr<Value> node; 214 scoped_ptr<Value> node;
215 215
216 switch (token.type) { 216 switch (token.type) {
217 case Token::END_OF_INPUT: 217 case Token::END_OF_INPUT:
218 case Token::INVALID_TOKEN: 218 case Token::INVALID_TOKEN:
219 return NULL; 219 return NULL;
220 220
221 case Token::NULL_TOKEN: 221 case Token::NULL_TOKEN:
222 node.reset(Value::CreateNullValue()); 222 node.reset(NullValue());
223 break; 223 break;
224 224
225 case Token::BOOL_TRUE: 225 case Token::BOOL_TRUE:
226 node.reset(Value::CreateBooleanValue(true)); 226 node.reset(TrueValue());
227 break; 227 break;
228 228
229 case Token::BOOL_FALSE: 229 case Token::BOOL_FALSE:
230 node.reset(Value::CreateBooleanValue(false)); 230 node.reset(FalseValue());
231 break; 231 break;
232 232
233 case Token::NUMBER: 233 case Token::NUMBER:
234 node.reset(DecodeNumber(token)); 234 node.reset(DecodeNumber(token));
235 if (!node.get()) 235 if (!node.get())
236 return NULL; 236 return NULL;
237 break; 237 break;
238 238
239 case Token::STRING: 239 case Token::STRING:
240 node.reset(DecodeString(token)); 240 node.reset(DecodeString(token));
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 } 385 }
386 386
387 return token; 387 return token;
388 } 388 }
389 389
390 Value* JSONReader::DecodeNumber(const Token& token) { 390 Value* JSONReader::DecodeNumber(const Token& token) {
391 const std::wstring num_string(token.begin, token.length); 391 const std::wstring num_string(token.begin, token.length);
392 392
393 int num_int; 393 int num_int;
394 if (StringToInt(WideToUTF8(num_string), &num_int)) 394 if (StringToInt(WideToUTF8(num_string), &num_int))
395 return Value::CreateIntegerValue(num_int); 395 return NumberValue::New(num_int);
396 396
397 double num_double; 397 double num_double;
398 if (StringToDouble(WideToUTF8(num_string), &num_double) && 398 if (StringToDouble(WideToUTF8(num_string), &num_double) &&
399 base::IsFinite(num_double)) 399 base::IsFinite(num_double))
400 return Value::CreateDoubleValue(num_double); 400 return NumberValue::New(num_double);
401 401
402 return NULL; 402 return NULL;
403 } 403 }
404 404
405 JSONReader::Token JSONReader::ParseStringToken() { 405 JSONReader::Token JSONReader::ParseStringToken() {
406 Token token(Token::STRING, json_pos_, 1); 406 Token token(Token::STRING, json_pos_, 1);
407 wchar_t c = token.NextChar(); 407 wchar_t c = token.NextChar();
408 while ('\0' != c) { 408 while ('\0' != c) {
409 if ('\\' == c) { 409 if ('\\' == c) {
410 ++token.length; 410 ++token.length;
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
498 // We should only have valid strings at this point. If not, 498 // We should only have valid strings at this point. If not,
499 // ParseStringToken didn't do it's job. 499 // ParseStringToken didn't do it's job.
500 NOTREACHED(); 500 NOTREACHED();
501 return NULL; 501 return NULL;
502 } 502 }
503 } else { 503 } else {
504 // Not escaped 504 // Not escaped
505 decoded_str.push_back(c); 505 decoded_str.push_back(c);
506 } 506 }
507 } 507 }
508 return Value::CreateStringValue(WideToUTF16Hack(decoded_str)); 508 return StringValue::New(WideToUTF16Hack(decoded_str));
509 } 509 }
510 510
511 JSONReader::Token JSONReader::ParseToken() { 511 JSONReader::Token JSONReader::ParseToken() {
512 static const std::wstring kNullString(L"null"); 512 static const std::wstring kNullString(L"null");
513 static const std::wstring kTrueString(L"true"); 513 static const std::wstring kTrueString(L"true");
514 static const std::wstring kFalseString(L"false"); 514 static const std::wstring kFalseString(L"false");
515 515
516 EatWhitespaceAndComments(); 516 EatWhitespaceAndComments();
517 517
518 Token token(Token::INVALID_TOKEN, 0, 0); 518 Token token(Token::INVALID_TOKEN, 0, 0);
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
665 ++column_number; 665 ++column_number;
666 } 666 }
667 } 667 }
668 668
669 error_line_ = line_number; 669 error_line_ = line_number;
670 error_col_ = column_number; 670 error_col_ = column_number;
671 error_code_ = error; 671 error_code_ = error;
672 } 672 }
673 673
674 } // namespace base 674 } // namespace base
OLDNEW
« no previous file with comments | « no previous file | base/json/json_writer_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698