| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/scoped_ptr.h" | 9 #include "base/scoped_ptr.h" |
| 10 #include "base/string_number_conversions.h" |
| 10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
| 11 #include "base/utf_string_conversions.h" | 12 #include "base/utf_string_conversions.h" |
| 12 #include "base/values.h" | 13 #include "base/values.h" |
| 13 | 14 |
| 14 namespace base { | 15 namespace base { |
| 15 | 16 |
| 16 static const JSONReader::Token kInvalidToken(JSONReader::Token::INVALID_TOKEN, | 17 static const JSONReader::Token kInvalidToken(JSONReader::Token::INVALID_TOKEN, |
| 17 0, 0); | 18 0, 0); |
| 18 static const int kStackLimit = 100; | 19 static const int kStackLimit = 100; |
| 19 | 20 |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 return kInvalidToken; | 395 return kInvalidToken; |
| 395 } | 396 } |
| 396 | 397 |
| 397 return token; | 398 return token; |
| 398 } | 399 } |
| 399 | 400 |
| 400 Value* JSONReader::DecodeNumber(const Token& token) { | 401 Value* JSONReader::DecodeNumber(const Token& token) { |
| 401 const std::wstring num_string(token.begin, token.length); | 402 const std::wstring num_string(token.begin, token.length); |
| 402 | 403 |
| 403 int num_int; | 404 int num_int; |
| 404 if (StringToInt(WideToUTF16Hack(num_string), &num_int)) | 405 if (StringToInt(WideToUTF8(num_string), &num_int)) |
| 405 return Value::CreateIntegerValue(num_int); | 406 return Value::CreateIntegerValue(num_int); |
| 406 | 407 |
| 407 double num_double; | 408 double num_double; |
| 408 if (StringToDouble(WideToUTF16Hack(num_string), &num_double) && | 409 if (StringToDouble(WideToUTF8(num_string), &num_double) && |
| 409 base::IsFinite(num_double)) | 410 base::IsFinite(num_double)) |
| 410 return Value::CreateRealValue(num_double); | 411 return Value::CreateRealValue(num_double); |
| 411 | 412 |
| 412 return NULL; | 413 return NULL; |
| 413 } | 414 } |
| 414 | 415 |
| 415 JSONReader::Token JSONReader::ParseStringToken() { | 416 JSONReader::Token JSONReader::ParseStringToken() { |
| 416 Token token(Token::STRING, json_pos_, 1); | 417 Token token(Token::STRING, json_pos_, 1); |
| 417 wchar_t c = token.NextChar(); | 418 wchar_t c = token.NextChar(); |
| 418 while ('\0' != c) { | 419 while ('\0' != c) { |
| (...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 675 ++column_number; | 676 ++column_number; |
| 676 } | 677 } |
| 677 } | 678 } |
| 678 | 679 |
| 679 error_line_ = line_number; | 680 error_line_ = line_number; |
| 680 error_col_ = column_number; | 681 error_col_ = column_number; |
| 681 error_code_ = error; | 682 error_code_ = error; |
| 682 } | 683 } |
| 683 | 684 |
| 684 } // namespace base | 685 } // namespace base |
| OLD | NEW |