diff options
author | mitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-02 04:40:32 +0000 |
---|---|---|
committer | mitchellwrosen@chromium.org <mitchellwrosen@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-06-02 04:40:32 +0000 |
commit | 0bf68e2197b41abd19b4b58910a4a81d72b82023 (patch) | |
tree | 19487707e3cd492428853cbb7d3fa9bd3993d876 /base/json | |
parent | 97bdb2fe0a7dac64b534a255675943f0e6f96cdf (diff) | |
download | chromium_src-0bf68e2197b41abd19b4b58910a4a81d72b82023.zip chromium_src-0bf68e2197b41abd19b4b58910a4a81d72b82023.tar.gz chromium_src-0bf68e2197b41abd19b4b58910a4a81d72b82023.tar.bz2 |
Update JSONReader to take base::StringPiece instead of std::string
I also went through the source tree and fixed any now-unnecessary conversions
from base::StringPiece to std::string
BUG=114785
TEST=Manual
Review URL: https://chromiumcodereview.appspot.com/10003001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@140177 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/json')
-rw-r--r-- | base/json/json_parser.cc | 5 | ||||
-rw-r--r-- | base/json/json_parser.h | 2 | ||||
-rw-r--r-- | base/json/json_reader.cc | 6 | ||||
-rw-r--r-- | base/json/json_reader.h | 7 |
4 files changed, 11 insertions, 9 deletions
diff --git a/base/json/json_parser.cc b/base/json/json_parser.cc index 0fd5202..738da47 100644 --- a/base/json/json_parser.cc +++ b/base/json/json_parser.cc @@ -8,6 +8,7 @@ #include "base/logging.h" #include "base/memory/scoped_ptr.h" #include "base/string_number_conversions.h" +#include "base/string_piece.h" #include "base/string_util.h" #include "base/stringprintf.h" #include "base/third_party/icu/icu_utf.h" @@ -204,7 +205,7 @@ JSONParser::JSONParser(int options) JSONParser::~JSONParser() { } -Value* JSONParser::Parse(const std::string& input) { +Value* JSONParser::Parse(const StringPiece& input) { // TODO(rsesek): Windows has problems with StringPiece/hidden roots. Fix // <http://crbug.com/126107> when my Windows box arrives. #if defined(OS_WIN) @@ -216,7 +217,7 @@ Value* JSONParser::Parse(const std::string& input) { // be used, so do not bother copying the input because StringPiece will not // be used anywhere. if (!(options_ & JSON_DETACHABLE_CHILDREN)) { - input_copy = input; + input_copy = input.as_string(); start_pos_ = input_copy.data(); } else { start_pos_ = input.data(); diff --git a/base/json/json_parser.h b/base/json/json_parser.h index 901e679..56e49a2 100644 --- a/base/json/json_parser.h +++ b/base/json/json_parser.h @@ -66,7 +66,7 @@ class BASE_EXPORT_PRIVATE JSONParser { // Parses the input string according to the set options and returns the // result as a Value owned by the caller. - Value* Parse(const std::string& input); + Value* Parse(const StringPiece& input); // Returns the error code. JSONReader::JsonParseError error_code() const; diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc index fb1459b..593273e 100644 --- a/base/json/json_reader.cc +++ b/base/json/json_reader.cc @@ -38,20 +38,20 @@ JSONReader::~JSONReader() { } // static -Value* JSONReader::Read(const std::string& json) { +Value* JSONReader::Read(const StringPiece& json) { internal::JSONParser parser(JSON_PARSE_RFC); return parser.Parse(json); } // static -Value* JSONReader::Read(const std::string& json, +Value* JSONReader::Read(const StringPiece& json, int options) { internal::JSONParser parser(options); return parser.Parse(json); } // static -Value* JSONReader::ReadAndReturnError(const std::string& json, +Value* JSONReader::ReadAndReturnError(const StringPiece& json, int options, int* error_code_out, std::string* error_msg_out) { diff --git a/base/json/json_reader.h b/base/json/json_reader.h index e081175..a11102f 100644 --- a/base/json/json_reader.h +++ b/base/json/json_reader.h @@ -33,6 +33,7 @@ #include "base/base_export.h" #include "base/basictypes.h" +#include "base/string_piece.h" #include "base/memory/scoped_ptr.h" namespace base { @@ -95,18 +96,18 @@ class BASE_EXPORT JSONReader { // Reads and parses |json|, returning a Value. The caller owns the returned // instance. If |json| is not a properly formed JSON string, returns NULL. - static Value* Read(const std::string& json); + static Value* Read(const StringPiece& json); // Reads and parses |json|, returning a Value owned by the caller. The // parser respects the given |options|. If the input is not properly formed, // returns NULL. - static Value* Read(const std::string& json, int options); + static Value* Read(const StringPiece& json, int options); // Reads and parses |json| like Read(). |error_code_out| and |error_msg_out| // are optional. If specified and NULL is returned, they will be populated // an error code and a formatted error message (including error location if // appropriate). Otherwise, they will be unmodified. - static Value* ReadAndReturnError(const std::string& json, + static Value* ReadAndReturnError(const StringPiece& json, int options, // JSONParserOptions int* error_code_out, std::string* error_msg_out); |