diff options
author | timsteele@google.com <timsteele@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-21 19:29:25 +0000 |
---|---|---|
committer | timsteele@google.com <timsteele@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-01-21 19:29:25 +0000 |
commit | 0477554f0623c67b163f6fb5cf1ce2c0d53ee4aa (patch) | |
tree | 1e6ece023782452db351251e7d3df5926f6eea3b /chrome/browser/sync/engine/net | |
parent | 811cb260aea2b6edea92e3b900945b55570c75d4 (diff) | |
download | chromium_src-0477554f0623c67b163f6fb5cf1ce2c0d53ee4aa.zip chromium_src-0477554f0623c67b163f6fb5cf1ce2c0d53ee4aa.tar.gz chromium_src-0477554f0623c67b163f6fb5cf1ce2c0d53ee4aa.tar.bz2 |
Move two generic string split functions from sync API to their own API in base/string_split.
BUG=None
TEST=base_unittests
Original patch by Thiago Farina
Original Review: http://codereview.chromium.org/464075
Review URL: http://codereview.chromium.org/502074
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@36774 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/sync/engine/net')
-rw-r--r-- | chrome/browser/sync/engine/net/gaia_authenticator.cc | 65 |
1 files changed, 4 insertions, 61 deletions
diff --git a/chrome/browser/sync/engine/net/gaia_authenticator.cc b/chrome/browser/sync/engine/net/gaia_authenticator.cc index 3dfaae4..da263a9 100644 --- a/chrome/browser/sync/engine/net/gaia_authenticator.cc +++ b/chrome/browser/sync/engine/net/gaia_authenticator.cc @@ -10,7 +10,7 @@ #include "base/basictypes.h" #include "base/port.h" -#include "base/string_util.h" +#include "base/string_split.h" #include "chrome/browser/sync/engine/all_status.h" #include "chrome/browser/sync/engine/net/http_return.h" #include "chrome/browser/sync/engine/net/url_translator.h" @@ -21,63 +21,6 @@ using std::pair; using std::string; using std::vector; -// TODO(timsteele): Integrate the following two functions to string_util.h or -// somewhere that makes them unit-testable. -bool SplitStringIntoKeyValues(const string& line, - char key_value_delimiter, - string* key, vector<string>* values) { - key->clear(); - values->clear(); - - // find the key string - size_t end_key_pos = line.find_first_of(key_value_delimiter); - if (end_key_pos == string::npos) { - DLOG(INFO) << "cannot parse key from line: " << line; - return false; // no key - } - key->assign(line, 0, end_key_pos); - - // find the values string - string remains(line, end_key_pos, line.size() - end_key_pos); - size_t begin_values_pos = remains.find_first_not_of(key_value_delimiter); - if (begin_values_pos == string::npos) { - DLOG(INFO) << "cannot parse value from line: " << line; - return false; // no value - } - string values_string(remains, begin_values_pos, - remains.size() - begin_values_pos); - - // construct the values vector - values->push_back(values_string); - return true; -} - -bool SplitStringIntoKeyValuePairs(const string& line, - char key_value_delimiter, - char key_value_pair_delimiter, - vector<pair<string, string> >* kv_pairs) { - kv_pairs->clear(); - - vector<string> pairs; - SplitString(line, key_value_pair_delimiter, &pairs); - - bool success = true; - for (size_t i = 0; i < pairs.size(); ++i) { - string key; - vector<string> value; - if (!SplitStringIntoKeyValues(pairs[i], - key_value_delimiter, - &key, &value)) { - // Don't return here, to allow for keys without associated - // values; just record that our split failed. - success = false; - } - DCHECK_LE(value.size(), 1U); - kv_pairs->push_back(make_pair(key, value.empty()? "" : value[0])); - } - return success; -} - namespace browser_sync { static const char kGaiaV1IssueAuthTokenPath[] = "/accounts/IssueAuthToken"; @@ -288,7 +231,7 @@ bool GaiaAuthenticator::LookupEmail(AuthResults* results) { } else if (RC_REQUEST_OK == server_response_code) { typedef vector<pair<string, string> > Tokens; Tokens tokens; - SplitStringIntoKeyValuePairs(message_text, '=', '\n', &tokens); + base::SplitStringIntoKeyValuePairs(message_text, '=', '\n', &tokens); for (Tokens::iterator i = tokens.begin(); i != tokens.end(); ++i) { if ("accountType" == i->first) { // We never authenticate an email as a hosted account. @@ -356,7 +299,7 @@ bool GaiaAuthenticator::IssueAuthToken(AuthResults* results, void GaiaAuthenticator::ExtractTokensFrom(const string& response, AuthResults* results) { vector<pair<string, string> > tokens; - SplitStringIntoKeyValuePairs(response, '=', '\n', &tokens); + base::SplitStringIntoKeyValuePairs(response, '=', '\n', &tokens); for (vector<pair<string, string> >::iterator i = tokens.begin(); i != tokens.end(); ++i) { if (i->first == "SID") { @@ -374,7 +317,7 @@ void GaiaAuthenticator::ExtractTokensFrom(const string& response, void GaiaAuthenticator::ExtractAuthErrorFrom(const string& response, AuthResults* results) { vector<pair<string, string> > tokens; - SplitStringIntoKeyValuePairs(response, '=', '\n', &tokens); + base::SplitStringIntoKeyValuePairs(response, '=', '\n', &tokens); for (vector<pair<string, string> >::iterator i = tokens.begin(); i != tokens.end(); ++i) { if (i->first == "Error") { |