| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/search_engines/template_url.h" | 5 #include "components/search_engines/template_url.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
| (...skipping 693 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 704 } else { | 704 } else { |
| 705 // Open brace without a closing brace, return. | 705 // Open brace without a closing brace, return. |
| 706 return std::string(); | 706 return std::string(); |
| 707 } | 707 } |
| 708 } | 708 } |
| 709 } | 709 } |
| 710 | 710 |
| 711 // Handles the post parameters. | 711 // Handles the post parameters. |
| 712 const std::string& post_params_string = GetPostParamsString(); | 712 const std::string& post_params_string = GetPostParamsString(); |
| 713 if (!post_params_string.empty()) { | 713 if (!post_params_string.empty()) { |
| 714 typedef std::vector<std::string> Strings; | 714 for (const base::StringPiece& cur : base::SplitStringPiece( |
| 715 Strings param_list; | 715 post_params_string, ",", |
| 716 base::SplitString(post_params_string, ',', ¶m_list); | 716 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL)) { |
| 717 | |
| 718 for (Strings::const_iterator iterator = param_list.begin(); | |
| 719 iterator != param_list.end(); ++iterator) { | |
| 720 Strings parts; | |
| 721 // The '=' delimiter is required and the name must be not empty. | 717 // The '=' delimiter is required and the name must be not empty. |
| 722 base::SplitString(*iterator, '=', &parts); | 718 std::vector<std::string> parts = base::SplitString( |
| 719 cur, "=", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 723 if ((parts.size() != 2U) || parts[0].empty()) | 720 if ((parts.size() != 2U) || parts[0].empty()) |
| 724 return std::string(); | 721 return std::string(); |
| 725 | 722 |
| 726 std::string& value = parts[1]; | 723 std::string& value = parts[1]; |
| 727 size_t replacements_size = replacements->size(); | 724 size_t replacements_size = replacements->size(); |
| 728 if (IsTemplateParameterString(value)) | 725 if (IsTemplateParameterString(value)) |
| 729 ParseParameter(0, value.length() - 1, &value, replacements); | 726 ParseParameter(0, value.length() - 1, &value, replacements); |
| 730 PostParam param = { parts[0], value }; | 727 PostParam param = { parts[0], value }; |
| 731 post_params->push_back(param); | 728 post_params->push_back(param); |
| 732 // If there was a replacement added, points its index to last added | 729 // If there was a replacement added, points its index to last added |
| (...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1509 // patterns. This means that given patterns | 1506 // patterns. This means that given patterns |
| 1510 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], | 1507 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], |
| 1511 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would | 1508 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would |
| 1512 // return false. This is important for at least Google, where such URLs | 1509 // return false. This is important for at least Google, where such URLs |
| 1513 // are invalid. | 1510 // are invalid. |
| 1514 return !search_terms->empty(); | 1511 return !search_terms->empty(); |
| 1515 } | 1512 } |
| 1516 } | 1513 } |
| 1517 return false; | 1514 return false; |
| 1518 } | 1515 } |
| OLD | NEW |