| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 "net/base/host_mapping_rules.h" | 5 #include "net/base/host_mapping_rules.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/string_split.h" | 8 #include "base/strings/string_split.h" |
| 9 #include "base/strings/string_tokenizer.h" | 9 #include "base/strings/string_tokenizer.h" |
| 10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 host_port->set_host(rule.replacement_hostname); | 59 host_port->set_host(rule.replacement_hostname); |
| 60 if (rule.replacement_port != -1) | 60 if (rule.replacement_port != -1) |
| 61 host_port->set_port(static_cast<uint16_t>(rule.replacement_port)); | 61 host_port->set_port(static_cast<uint16_t>(rule.replacement_port)); |
| 62 return true; | 62 return true; |
| 63 } | 63 } |
| 64 | 64 |
| 65 return false; | 65 return false; |
| 66 } | 66 } |
| 67 | 67 |
| 68 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { | 68 bool HostMappingRules::AddRuleFromString(const std::string& rule_string) { |
| 69 std::string trimmed; | 69 std::vector<std::string> parts = |
| 70 base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL, &trimmed); | 70 base::SplitString(base::TrimWhitespaceASCII(rule_string, base::TRIM_ALL), |
| 71 std::vector<std::string> parts; | 71 " ", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); |
| 72 base::SplitString(trimmed, ' ', &parts); | |
| 73 | 72 |
| 74 // Test for EXCLUSION rule. | 73 // Test for EXCLUSION rule. |
| 75 if (parts.size() == 2 && base::LowerCaseEqualsASCII(parts[0], "exclude")) { | 74 if (parts.size() == 2 && base::LowerCaseEqualsASCII(parts[0], "exclude")) { |
| 76 ExclusionRule rule; | 75 ExclusionRule rule; |
| 77 rule.hostname_pattern = base::StringToLowerASCII(parts[1]); | 76 rule.hostname_pattern = base::StringToLowerASCII(parts[1]); |
| 78 exclusion_rules_.push_back(rule); | 77 exclusion_rules_.push_back(rule); |
| 79 return true; | 78 return true; |
| 80 } | 79 } |
| 81 | 80 |
| 82 // Test for MAP rule. | 81 // Test for MAP rule. |
| (...skipping 18 matching lines...) Expand all Loading... |
| 101 map_rules_.clear(); | 100 map_rules_.clear(); |
| 102 | 101 |
| 103 base::StringTokenizer rules(rules_string, ","); | 102 base::StringTokenizer rules(rules_string, ","); |
| 104 while (rules.GetNext()) { | 103 while (rules.GetNext()) { |
| 105 bool ok = AddRuleFromString(rules.token()); | 104 bool ok = AddRuleFromString(rules.token()); |
| 106 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); | 105 LOG_IF(ERROR, !ok) << "Failed parsing rule: " << rules.token(); |
| 107 } | 106 } |
| 108 } | 107 } |
| 109 | 108 |
| 110 } // namespace net | 109 } // namespace net |
| OLD | NEW |