| OLD | NEW |
| 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_parser.h" | 5 #include "base/json/json_parser.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/string_number_conversions.h" | 10 #include "base/string_number_conversions.h" |
| 11 #include "base/string_piece.h" |
| 11 #include "base/string_util.h" | 12 #include "base/string_util.h" |
| 12 #include "base/stringprintf.h" | 13 #include "base/stringprintf.h" |
| 13 #include "base/third_party/icu/icu_utf.h" | 14 #include "base/third_party/icu/icu_utf.h" |
| 14 #include "base/utf_string_conversion_utils.h" | 15 #include "base/utf_string_conversion_utils.h" |
| 15 #include "base/utf_string_conversions.h" | 16 #include "base/utf_string_conversions.h" |
| 16 #include "base/values.h" | 17 #include "base/values.h" |
| 17 | 18 |
| 18 namespace base { | 19 namespace base { |
| 19 namespace internal { | 20 namespace internal { |
| 20 | 21 |
| (...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 197 line_number_(0), | 198 line_number_(0), |
| 198 index_last_line_(0), | 199 index_last_line_(0), |
| 199 error_code_(JSONReader::JSON_NO_ERROR), | 200 error_code_(JSONReader::JSON_NO_ERROR), |
| 200 error_line_(0), | 201 error_line_(0), |
| 201 error_column_(0) { | 202 error_column_(0) { |
| 202 } | 203 } |
| 203 | 204 |
| 204 JSONParser::~JSONParser() { | 205 JSONParser::~JSONParser() { |
| 205 } | 206 } |
| 206 | 207 |
| 207 Value* JSONParser::Parse(const std::string& input) { | 208 Value* JSONParser::Parse(const StringPiece& input) { |
| 208 // TODO(rsesek): Windows has problems with StringPiece/hidden roots. Fix | 209 // TODO(rsesek): Windows has problems with StringPiece/hidden roots. Fix |
| 209 // <http://crbug.com/126107> when my Windows box arrives. | 210 // <http://crbug.com/126107> when my Windows box arrives. |
| 210 #if defined(OS_WIN) | 211 #if defined(OS_WIN) |
| 211 options_ |= JSON_DETACHABLE_CHILDREN; | 212 options_ |= JSON_DETACHABLE_CHILDREN; |
| 212 #endif | 213 #endif |
| 213 | 214 |
| 214 std::string input_copy; | 215 std::string input_copy; |
| 215 // If the children of a JSON root can be detached, then hidden roots cannot | 216 // If the children of a JSON root can be detached, then hidden roots cannot |
| 216 // be used, so do not bother copying the input because StringPiece will not | 217 // be used, so do not bother copying the input because StringPiece will not |
| 217 // be used anywhere. | 218 // be used anywhere. |
| 218 if (!(options_ & JSON_DETACHABLE_CHILDREN)) { | 219 if (!(options_ & JSON_DETACHABLE_CHILDREN)) { |
| 219 input_copy = input; | 220 input_copy = input.as_string(); |
| 220 start_pos_ = input_copy.data(); | 221 start_pos_ = input_copy.data(); |
| 221 } else { | 222 } else { |
| 222 start_pos_ = input.data(); | 223 start_pos_ = input.data(); |
| 223 } | 224 } |
| 224 pos_ = start_pos_; | 225 pos_ = start_pos_; |
| 225 end_pos_ = start_pos_ + input.length(); | 226 end_pos_ = start_pos_ + input.length(); |
| 226 index_ = 0; | 227 index_ = 0; |
| 227 line_number_ = 1; | 228 line_number_ = 1; |
| 228 index_last_line_ = 0; | 229 index_last_line_ = 0; |
| 229 | 230 |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 const std::string& description) { | 961 const std::string& description) { |
| 961 if (line || column) { | 962 if (line || column) { |
| 962 return StringPrintf("Line: %i, column: %i, %s", | 963 return StringPrintf("Line: %i, column: %i, %s", |
| 963 line, column, description.c_str()); | 964 line, column, description.c_str()); |
| 964 } | 965 } |
| 965 return description; | 966 return description; |
| 966 } | 967 } |
| 967 | 968 |
| 968 } // namespace internal | 969 } // namespace internal |
| 969 } // namespace base | 970 } // namespace base |
| OLD | NEW |