Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(286)

Side by Side Diff: components/search_engines/template_url.cc

Issue 1200393002: Add more string_util functions to base namespace. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@string
Patch Set: Android Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 334 matching lines...) Expand 10 before | Expand all | Expand 10 after
345 bool TemplateURLRef::IsValid(const SearchTermsData& search_terms_data) const { 345 bool TemplateURLRef::IsValid(const SearchTermsData& search_terms_data) const {
346 ParseIfNecessary(search_terms_data); 346 ParseIfNecessary(search_terms_data);
347 return valid_; 347 return valid_;
348 } 348 }
349 349
350 base::string16 TemplateURLRef::DisplayURL( 350 base::string16 TemplateURLRef::DisplayURL(
351 const SearchTermsData& search_terms_data) const { 351 const SearchTermsData& search_terms_data) const {
352 ParseIfNecessary(search_terms_data); 352 ParseIfNecessary(search_terms_data);
353 std::string result(GetURL()); 353 std::string result(GetURL());
354 if (valid_ && !replacements_.empty()) { 354 if (valid_ && !replacements_.empty()) {
355 ReplaceSubstringsAfterOffset(&result, 0, 355 base::ReplaceSubstringsAfterOffset(&result, 0,
356 kSearchTermsParameterFull, 356 kSearchTermsParameterFull,
357 kDisplaySearchTerms); 357 kDisplaySearchTerms);
358 ReplaceSubstringsAfterOffset(&result, 0, 358 base::ReplaceSubstringsAfterOffset(&result, 0,
359 kGoogleUnescapedSearchTermsParameterFull, 359 kGoogleUnescapedSearchTermsParameterFull,
360 kDisplayUnescapedSearchTerms); 360 kDisplayUnescapedSearchTerms);
361 } 361 }
362 return base::UTF8ToUTF16(result); 362 return base::UTF8ToUTF16(result);
363 } 363 }
364 364
365 // static 365 // static
366 std::string TemplateURLRef::DisplayURLToURLRef( 366 std::string TemplateURLRef::DisplayURLToURLRef(
367 const base::string16& display_url) { 367 const base::string16& display_url) {
368 std::string result = base::UTF16ToUTF8(display_url); 368 std::string result = base::UTF16ToUTF8(display_url);
369 ReplaceSubstringsAfterOffset(&result, 0, 369 base::ReplaceSubstringsAfterOffset(&result, 0,
370 kDisplaySearchTerms, 370 kDisplaySearchTerms,
371 kSearchTermsParameterFull); 371 kSearchTermsParameterFull);
372 ReplaceSubstringsAfterOffset(&result, 0, 372 base::ReplaceSubstringsAfterOffset(&result, 0,
373 kDisplayUnescapedSearchTerms, 373 kDisplayUnescapedSearchTerms,
374 kGoogleUnescapedSearchTermsParameterFull); 374 kGoogleUnescapedSearchTermsParameterFull);
375 return result; 375 return result;
376 } 376 }
377 377
378 const std::string& TemplateURLRef::GetHost( 378 const std::string& TemplateURLRef::GetHost(
379 const SearchTermsData& search_terms_data) const { 379 const SearchTermsData& search_terms_data) const {
380 ParseIfNecessary(search_terms_data); 380 ParseIfNecessary(search_terms_data);
381 return host_; 381 return host_;
382 } 382 }
383 383
384 const std::string& TemplateURLRef::GetPath( 384 const std::string& TemplateURLRef::GetPath(
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
770 // could be more than one term, but it's uncommon; so we punt. 770 // could be more than one term, but it's uncommon; so we punt.
771 if (has_only_one_search_term) 771 if (has_only_one_search_term)
772 ParseHostAndSearchTermKey(search_terms_data); 772 ParseHostAndSearchTermKey(search_terms_data);
773 } 773 }
774 } 774 }
775 } 775 }
776 776
777 void TemplateURLRef::ParseHostAndSearchTermKey( 777 void TemplateURLRef::ParseHostAndSearchTermKey(
778 const SearchTermsData& search_terms_data) const { 778 const SearchTermsData& search_terms_data) const {
779 std::string url_string(GetURL()); 779 std::string url_string(GetURL());
780 ReplaceSubstringsAfterOffset(&url_string, 0, "{google:baseURL}", 780 base::ReplaceSubstringsAfterOffset(
781 search_terms_data.GoogleBaseURLValue()); 781 &url_string, 0, "{google:baseURL}",
782 ReplaceSubstringsAfterOffset(&url_string, 0, "{google:baseSuggestURL}", 782 search_terms_data.GoogleBaseURLValue());
783 search_terms_data.GoogleBaseSuggestURLValue()); 783 base::ReplaceSubstringsAfterOffset(
784 &url_string, 0, "{google:baseSuggestURL}",
785 search_terms_data.GoogleBaseSuggestURLValue());
784 786
785 search_term_key_.clear(); 787 search_term_key_.clear();
786 search_term_position_in_path_ = std::string::npos; 788 search_term_position_in_path_ = std::string::npos;
787 host_.clear(); 789 host_.clear();
788 path_.clear(); 790 path_.clear();
789 search_term_key_location_ = url::Parsed::QUERY; 791 search_term_key_location_ = url::Parsed::QUERY;
790 792
791 GURL url(url_string); 793 GURL url(url_string);
792 if (!url.is_valid()) 794 if (!url.is_valid())
793 return; 795 return;
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
1508 // patterns. This means that given patterns 1510 // patterns. This means that given patterns
1509 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ], 1511 // [ "http://foo/#q={searchTerms}", "http://foo/?q={searchTerms}" ],
1510 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would 1512 // calling ExtractSearchTermsFromURL() on "http://foo/?q=bar#q=' would
1511 // return false. This is important for at least Google, where such URLs 1513 // return false. This is important for at least Google, where such URLs
1512 // are invalid. 1514 // are invalid.
1513 return !search_terms->empty(); 1515 return !search_terms->empty();
1514 } 1516 }
1515 } 1517 }
1516 return false; 1518 return false;
1517 } 1519 }
OLDNEW
« no previous file with comments | « components/password_manager/core/browser/import/csv_reader.cc ('k') | components/search_engines/template_url_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698