| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 #ifndef URL_URL_PARSE_INTERNAL_H_ | 5 #ifndef URL_URL_PARSE_INTERNAL_H_ |
| 6 #define URL_URL_PARSE_INTERNAL_H_ | 6 #define URL_URL_PARSE_INTERNAL_H_ |
| 7 | 7 |
| 8 // Contains common inline helper functions used by the URL parsing routines. | 8 // Contains common inline helper functions used by the URL parsing routines. |
| 9 | 9 |
| 10 #include "url/url_parse.h" | 10 #include "url/url_parse.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 inline bool ShouldTrimFromURL(base::char16 ch) { | 21 inline bool ShouldTrimFromURL(base::char16 ch) { |
| 22 return ch <= ' '; | 22 return ch <= ' '; |
| 23 } | 23 } |
| 24 | 24 |
| 25 // Given an already-initialized begin index and length, this shrinks the range | 25 // Given an already-initialized begin index and length, this shrinks the range |
| 26 // to eliminate "should-be-trimmed" characters. Note that the length does *not* | 26 // to eliminate "should-be-trimmed" characters. Note that the length does *not* |
| 27 // indicate the length of untrimmed data from |*begin|, but rather the position | 27 // indicate the length of untrimmed data from |*begin|, but rather the position |
| 28 // in the input string (so the string starts at character |*begin| in the spec, | 28 // in the input string (so the string starts at character |*begin| in the spec, |
| 29 // and goes until |*len|). | 29 // and goes until |*len|). |
| 30 template<typename CHAR> | 30 template<typename CHAR> |
| 31 inline void TrimURL(const CHAR* spec, int* begin, int* len) { | 31 inline void TrimURL(const CHAR* spec, int* begin, int* len, |
| 32 bool trim_path_end = true) { |
| 32 // Strip leading whitespace and control characters. | 33 // Strip leading whitespace and control characters. |
| 33 while (*begin < *len && ShouldTrimFromURL(spec[*begin])) | 34 while (*begin < *len && ShouldTrimFromURL(spec[*begin])) |
| 34 (*begin)++; | 35 (*begin)++; |
| 35 | 36 |
| 36 // Strip trailing whitespace and control characters. We need the >i test for | 37 if (trim_path_end) { |
| 37 // when the input string is all blanks; we don't want to back past the input. | 38 // Strip trailing whitespace and control characters. We need the >i test |
| 38 while (*len > *begin && ShouldTrimFromURL(spec[*len - 1])) | 39 // for when the input string is all blanks; we don't want to back past the |
| 39 (*len)--; | 40 // input. |
| 41 while (*len > *begin && ShouldTrimFromURL(spec[*len - 1])) |
| 42 (*len)--; |
| 43 } |
| 40 } | 44 } |
| 41 | 45 |
| 42 // Counts the number of consecutive slashes starting at the given offset | 46 // Counts the number of consecutive slashes starting at the given offset |
| 43 // in the given string of the given length. | 47 // in the given string of the given length. |
| 44 template<typename CHAR> | 48 template<typename CHAR> |
| 45 inline int CountConsecutiveSlashes(const CHAR *str, | 49 inline int CountConsecutiveSlashes(const CHAR *str, |
| 46 int begin_offset, int str_len) { | 50 int begin_offset, int str_len) { |
| 47 int count = 0; | 51 int count = 0; |
| 48 while (begin_offset + count < str_len && | 52 while (begin_offset + count < str_len && |
| 49 IsURLSlash(str[begin_offset + count])) | 53 IsURLSlash(str[begin_offset + count])) |
| (...skipping 28 matching lines...) Expand all Loading... |
| 78 int after_scheme, | 82 int after_scheme, |
| 79 Parsed* parsed); | 83 Parsed* parsed); |
| 80 void ParseAfterScheme(const base::char16* spec, | 84 void ParseAfterScheme(const base::char16* spec, |
| 81 int spec_len, | 85 int spec_len, |
| 82 int after_scheme, | 86 int after_scheme, |
| 83 Parsed* parsed); | 87 Parsed* parsed); |
| 84 | 88 |
| 85 } // namespace url_parse | 89 } // namespace url_parse |
| 86 | 90 |
| 87 #endif // URL_URL_PARSE_INTERNAL_H_ | 91 #endif // URL_URL_PARSE_INTERNAL_H_ |
| OLD | NEW |