Chromium Code Reviews| 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/content_settings/core/common/content_settings_pattern.h" | 5 #include "components/content_settings/core/common/content_settings_pattern.h" |
| 6 | 6 |
| 7 #include <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/string_split.h" | 10 #include "base/strings/string_split.h" |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 40 if (match == std::string::npos || | 40 if (match == std::string::npos || |
| 41 (match > 0 && sub_domain[match - 1] != '.') || | 41 (match > 0 && sub_domain[match - 1] != '.') || |
| 42 (match + domain.length() != sub_domain.length())) { | 42 (match + domain.length() != sub_domain.length())) { |
| 43 return false; | 43 return false; |
| 44 } | 44 } |
| 45 return true; | 45 return true; |
| 46 } | 46 } |
| 47 | 47 |
| 48 // Compares two domain names. | 48 // Compares two domain names. |
| 49 int CompareDomainNames(const std::string& str1, const std::string& str2) { | 49 int CompareDomainNames(const std::string& str1, const std::string& str2) { |
| 50 std::vector<std::string> domain_name1; | 50 std::vector<base::StringPiece> domain_name1 = base::SplitStringPiece( |
| 51 std::vector<std::string> domain_name2; | 51 str1, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
|
yzshen1
2015/07/22 22:50:34
TRIM_WHITESPACE
| |
| 52 | 52 std::vector<base::StringPiece> domain_name2 = base::SplitStringPiece( |
| 53 base::SplitString(str1, '.', &domain_name1); | 53 str2, ".", base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
|
yzshen1
2015/07/22 22:50:34
TRIM_WHITESPACE
| |
| 54 base::SplitString(str2, '.', &domain_name2); | |
| 55 | 54 |
| 56 int i1 = static_cast<int>(domain_name1.size()) - 1; | 55 int i1 = static_cast<int>(domain_name1.size()) - 1; |
| 57 int i2 = static_cast<int>(domain_name2.size()) - 1; | 56 int i2 = static_cast<int>(domain_name2.size()) - 1; |
| 58 int rv; | 57 int rv; |
| 59 while (i1 >= 0 && i2 >= 0) { | 58 while (i1 >= 0 && i2 >= 0) { |
| 60 // domain names are stored in puny code. So it's fine to use the compare | 59 // Domain names are stored in puny code. So it's fine to use the compare |
| 61 // method. | 60 // method. |
| 62 rv = domain_name1[i1].compare(domain_name2[i2]); | 61 rv = domain_name1[i1].compare(domain_name2[i2]); |
| 63 if (rv != 0) | 62 if (rv != 0) |
| 64 return rv; | 63 return rv; |
| 65 --i1; | 64 --i1; |
| 66 --i2; | 65 --i2; |
| 67 } | 66 } |
| 68 | 67 |
| 69 if (i1 > i2) | 68 if (i1 > i2) |
| 70 return 1; | 69 return 1; |
| (...skipping 631 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 702 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) | 701 if (!parts.is_port_wildcard && other_parts.is_port_wildcard) |
| 703 return ContentSettingsPattern::PREDECESSOR; | 702 return ContentSettingsPattern::PREDECESSOR; |
| 704 | 703 |
| 705 int result = parts.port.compare(other_parts.port); | 704 int result = parts.port.compare(other_parts.port); |
| 706 if (result == 0) | 705 if (result == 0) |
| 707 return ContentSettingsPattern::IDENTITY; | 706 return ContentSettingsPattern::IDENTITY; |
| 708 if (result > 0) | 707 if (result > 0) |
| 709 return ContentSettingsPattern::DISJOINT_ORDER_PRE; | 708 return ContentSettingsPattern::DISJOINT_ORDER_PRE; |
| 710 return ContentSettingsPattern::DISJOINT_ORDER_POST; | 709 return ContentSettingsPattern::DISJOINT_ORDER_POST; |
| 711 } | 710 } |
| OLD | NEW |