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 "extensions/common/url_pattern.h" | 5 #include "extensions/common/url_pattern.h" |
6 | 6 |
7 #include <ostream> | 7 #include <ostream> |
8 | 8 |
9 #include "base/strings/pattern.h" | 9 #include "base/strings/pattern.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
230 // Host is required. | 230 // Host is required. |
231 if (host_start_pos == host_end_pos) | 231 if (host_start_pos == host_end_pos) |
232 return PARSE_ERROR_EMPTY_HOST; | 232 return PARSE_ERROR_EMPTY_HOST; |
233 | 233 |
234 if (host_end_pos == std::string::npos) | 234 if (host_end_pos == std::string::npos) |
235 return PARSE_ERROR_EMPTY_PATH; | 235 return PARSE_ERROR_EMPTY_PATH; |
236 | 236 |
237 host_ = pattern.substr(host_start_pos, host_end_pos - host_start_pos); | 237 host_ = pattern.substr(host_start_pos, host_end_pos - host_start_pos); |
238 | 238 |
239 // The first component can optionally be '*' to match all subdomains. | 239 // The first component can optionally be '*' to match all subdomains. |
240 std::vector<std::string> host_components = base::SplitString( | 240 std::vector<std::string> host_components; |
241 host_, ".", base::TRIM_WHITESPACE, base::SPLIT_WANT_ALL); | 241 base::SplitString(host_, '.', &host_components); |
242 | 242 |
243 // Could be empty if the host only consists of whitespace characters. | 243 // Could be empty if the host only consists of whitespace characters. |
244 if (host_components.empty() || | 244 if (host_components.empty()) |
245 (host_components.size() == 1 && host_components[0].empty())) | |
246 return PARSE_ERROR_EMPTY_HOST; | 245 return PARSE_ERROR_EMPTY_HOST; |
247 | 246 |
248 if (host_components[0] == "*") { | 247 if (host_components[0] == "*") { |
249 match_subdomains_ = true; | 248 match_subdomains_ = true; |
250 host_components.erase(host_components.begin(), | 249 host_components.erase(host_components.begin(), |
251 host_components.begin() + 1); | 250 host_components.begin() + 1); |
252 } | 251 } |
253 host_ = base::JoinString(host_components, "."); | 252 host_ = base::JoinString(host_components, "."); |
254 | 253 |
255 path_start_pos = host_end_pos; | 254 path_start_pos = host_end_pos; |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
607 } | 606 } |
608 | 607 |
609 return result; | 608 return result; |
610 } | 609 } |
611 | 610 |
612 // static | 611 // static |
613 const char* URLPattern::GetParseResultString( | 612 const char* URLPattern::GetParseResultString( |
614 URLPattern::ParseResult parse_result) { | 613 URLPattern::ParseResult parse_result) { |
615 return kParseResultMessages[parse_result]; | 614 return kParseResultMessages[parse_result]; |
616 } | 615 } |
OLD | NEW |