OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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_fixer.h" | 5 #include "components/url_formatter/url_fixer.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <algorithm> | 9 #include <algorithm> |
10 | 10 |
(...skipping 462 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
473 | 473 |
474 // We need to add a scheme in order for ParseStandardURL to be happy. | 474 // We need to add a scheme in order for ParseStandardURL to be happy. |
475 // Find the first non-whitespace character. | 475 // Find the first non-whitespace character. |
476 std::string::iterator first_nonwhite = text->begin(); | 476 std::string::iterator first_nonwhite = text->begin(); |
477 while ((first_nonwhite != text->end()) && | 477 while ((first_nonwhite != text->end()) && |
478 base::IsUnicodeWhitespace(*first_nonwhite)) | 478 base::IsUnicodeWhitespace(*first_nonwhite)) |
479 ++first_nonwhite; | 479 ++first_nonwhite; |
480 | 480 |
481 // Construct the text to parse by inserting the scheme. | 481 // Construct the text to parse by inserting the scheme. |
482 std::string inserted_text(scheme); | 482 std::string inserted_text(scheme); |
483 inserted_text.append(url::kStandardSchemeSeparator); | 483 if (first_nonwhite == text->end() || *first_nonwhite != ':') |
484 inserted_text.append(url::kStandardSchemeSeparator); // Add "://". | |
Peter Kasting
2016/10/05 00:56:30
Nit: After your explanation, I understand why this
brettw
2016/10/05 05:10:12
I did the second.
| |
484 std::string text_to_parse(text->begin(), first_nonwhite); | 485 std::string text_to_parse(text->begin(), first_nonwhite); |
485 text_to_parse.append(inserted_text); | 486 text_to_parse.append(inserted_text); |
486 text_to_parse.append(first_nonwhite, text->end()); | 487 text_to_parse.append(first_nonwhite, text->end()); |
487 | 488 |
488 // Have the GURL parser do the heavy lifting for us. | 489 // Have the GURL parser do the heavy lifting for us. |
489 url::ParseStandardURL(text_to_parse.data(), | 490 url::ParseStandardURL(text_to_parse.data(), |
490 static_cast<int>(text_to_parse.length()), parts); | 491 static_cast<int>(text_to_parse.length()), parts); |
491 | 492 |
492 // Offset the results of the parse to match the original text. | 493 // Offset the results of the parse to match the original text. |
493 const int offset = -static_cast<int>(inserted_text.length()); | 494 const int offset = -static_cast<int>(inserted_text.length()); |
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
675 } | 676 } |
676 | 677 |
677 bool IsEquivalentScheme(const std::string& scheme1, | 678 bool IsEquivalentScheme(const std::string& scheme1, |
678 const std::string& scheme2) { | 679 const std::string& scheme2) { |
679 return scheme1 == scheme2 || | 680 return scheme1 == scheme2 || |
680 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || | 681 (scheme1 == url::kAboutScheme && scheme2 == kChromeUIScheme) || |
681 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); | 682 (scheme1 == kChromeUIScheme && scheme2 == url::kAboutScheme); |
682 } | 683 } |
683 | 684 |
684 } // namespace url_formatter | 685 } // namespace url_formatter |
OLD | NEW |