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

Side by Side Diff: components/url_formatter/url_formatter.cc

Issue 2953943003: base::OffsetAdjuster: Refactor offset limiting logic into the base::OffsetAdjuster (Closed)
Patch Set: fix test Created 3 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
« no previous file with comments | « base/strings/utf_offset_string_conversions_unittest.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/url_formatter/url_formatter.h" 5 #include "components/url_formatter/url_formatter.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <utility> 8 #include <utility>
9 #include <vector> 9 #include <vector>
10 10
(...skipping 400 matching lines...) Expand 10 before | Expand all | Expand 10 after
411 const FormatUrlType kFormatUrlExperimentalElideAfterHost = 1 << 3; 411 const FormatUrlType kFormatUrlExperimentalElideAfterHost = 1 << 3;
412 const FormatUrlType kFormatUrlExperimentalOmitHTTPS = 1 << 4; 412 const FormatUrlType kFormatUrlExperimentalOmitHTTPS = 1 << 4;
413 const FormatUrlType kFormatUrlExperimentalOmitTrivialSubdomains = 1 << 5; 413 const FormatUrlType kFormatUrlExperimentalOmitTrivialSubdomains = 1 << 5;
414 414
415 base::string16 FormatUrl(const GURL& url, 415 base::string16 FormatUrl(const GURL& url,
416 FormatUrlTypes format_types, 416 FormatUrlTypes format_types,
417 net::UnescapeRule::Type unescape_rules, 417 net::UnescapeRule::Type unescape_rules,
418 url::Parsed* new_parsed, 418 url::Parsed* new_parsed,
419 size_t* prefix_end, 419 size_t* prefix_end,
420 size_t* offset_for_adjustment) { 420 size_t* offset_for_adjustment) {
421 std::vector<size_t> offsets; 421 base::OffsetAdjuster::Adjustments adjustments;
422 if (offset_for_adjustment) 422 base::string16 result = FormatUrlWithAdjustments(
423 offsets.push_back(*offset_for_adjustment); 423 url, format_types, unescape_rules, new_parsed, prefix_end, &adjustments);
424 base::string16 result = 424 if (offset_for_adjustment) {
425 FormatUrlWithOffsets(url, format_types, unescape_rules, new_parsed, 425 base::OffsetAdjuster::AdjustOffset(adjustments, offset_for_adjustment,
426 prefix_end, &offsets); 426 result.length());
427 if (offset_for_adjustment) 427 }
428 *offset_for_adjustment = offsets[0];
429 return result; 428 return result;
430 } 429 }
431 430
432 base::string16 FormatUrlWithOffsets( 431 base::string16 FormatUrlWithOffsets(
433 const GURL& url, 432 const GURL& url,
434 FormatUrlTypes format_types, 433 FormatUrlTypes format_types,
435 net::UnescapeRule::Type unescape_rules, 434 net::UnescapeRule::Type unescape_rules,
436 url::Parsed* new_parsed, 435 url::Parsed* new_parsed,
437 size_t* prefix_end, 436 size_t* prefix_end,
438 std::vector<size_t>* offsets_for_adjustment) { 437 std::vector<size_t>* offsets_for_adjustment) {
439 base::OffsetAdjuster::Adjustments adjustments; 438 base::OffsetAdjuster::Adjustments adjustments;
440 const base::string16& format_url_return_value = 439 const base::string16& result = FormatUrlWithAdjustments(
441 FormatUrlWithAdjustments(url, format_types, unescape_rules, new_parsed, 440 url, format_types, unescape_rules, new_parsed, prefix_end, &adjustments);
442 prefix_end, &adjustments); 441 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment,
443 base::OffsetAdjuster::AdjustOffsets(adjustments, offsets_for_adjustment); 442 result.length());
444 if (offsets_for_adjustment) { 443 return result;
445 std::for_each(
446 offsets_for_adjustment->begin(), offsets_for_adjustment->end(),
447 base::LimitOffset<std::string>(format_url_return_value.length()));
448 }
449 return format_url_return_value;
450 } 444 }
451 445
452 base::string16 FormatUrlWithAdjustments( 446 base::string16 FormatUrlWithAdjustments(
453 const GURL& url, 447 const GURL& url,
454 FormatUrlTypes format_types, 448 FormatUrlTypes format_types,
455 net::UnescapeRule::Type unescape_rules, 449 net::UnescapeRule::Type unescape_rules,
456 url::Parsed* new_parsed, 450 url::Parsed* new_parsed,
457 size_t* prefix_end, 451 size_t* prefix_end,
458 base::OffsetAdjuster::Adjustments* adjustments) { 452 base::OffsetAdjuster::Adjustments* adjustments) {
459 DCHECK(adjustments != NULL); 453 DCHECK(adjustments);
460 adjustments->clear(); 454 adjustments->clear();
461 url::Parsed parsed_temp; 455 url::Parsed parsed_temp;
462 if (!new_parsed) 456 if (!new_parsed)
463 new_parsed = &parsed_temp; 457 new_parsed = &parsed_temp;
464 else 458 else
465 *new_parsed = url::Parsed(); 459 *new_parsed = url::Parsed();
466 460
467 // Special handling for view-source:. Don't use content::kViewSourceScheme 461 // Special handling for view-source:. Don't use content::kViewSourceScheme
468 // because this library shouldn't depend on chrome. 462 // because this library shouldn't depend on chrome.
469 const char kViewSource[] = "view-source"; 463 const char kViewSource[] = "view-source";
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 return base::StartsWith(text, www, base::CompareCase::SENSITIVE) 652 return base::StartsWith(text, www, base::CompareCase::SENSITIVE)
659 ? text.substr(www.length()) : text; 653 ? text.substr(www.length()) : text;
660 } 654 }
661 655
662 base::string16 StripWWWFromHost(const GURL& url) { 656 base::string16 StripWWWFromHost(const GURL& url) {
663 DCHECK(url.is_valid()); 657 DCHECK(url.is_valid());
664 return StripWWW(base::ASCIIToUTF16(url.host_piece())); 658 return StripWWW(base::ASCIIToUTF16(url.host_piece()));
665 } 659 }
666 660
667 } // namespace url_formatter 661 } // namespace url_formatter
OLDNEW
« no previous file with comments | « base/strings/utf_offset_string_conversions_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698