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
3 // found in the LICENSE file.
5 #ifndef URL_URL_PARSE_INTERNAL_H_
6 #define URL_URL_PARSE_INTERNAL_H_
8 // Contains common inline helper functions used by the URL parsing routines.
10 #include "url/url_parse.h"
14 // We treat slashes and backslashes the same for IE compatability.
15 inline bool IsURLSlash(base::char16 ch
) {
16 return ch
== '/' || ch
== '\\';
19 // Returns true if we should trim this character from the URL because it is a
20 // space or a control character.
21 inline bool ShouldTrimFromURL(base::char16 ch
) {
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*
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,
29 // and goes until |*len|).
30 template<typename CHAR
>
31 inline void TrimURL(const CHAR
* spec
, int* begin
, int* len
,
32 bool trim_path_end
= true) {
33 // Strip leading whitespace and control characters.
34 while (*begin
< *len
&& ShouldTrimFromURL(spec
[*begin
]))
38 // Strip trailing whitespace and control characters. We need the >i test
39 // for when the input string is all blanks; we don't want to back past the
41 while (*len
> *begin
&& ShouldTrimFromURL(spec
[*len
- 1]))
46 // Counts the number of consecutive slashes starting at the given offset
47 // in the given string of the given length.
48 template<typename CHAR
>
49 inline int CountConsecutiveSlashes(const CHAR
*str
,
50 int begin_offset
, int str_len
) {
52 while (begin_offset
+ count
< str_len
&&
53 IsURLSlash(str
[begin_offset
+ count
]))
58 // Internal functions in url_parse.cc that parse the path, that is, everything
59 // following the authority section. The input is the range of everything
60 // following the authority section, and the output is the identified ranges.
62 // This is designed for the file URL parser or other consumers who may do
63 // special stuff at the beginning, but want regular path parsing, it just
64 // maps to the internal parsing function for paths.
65 void ParsePathInternal(const char* spec
,
66 const Component
& path
,
70 void ParsePathInternal(const base::char16
* spec
,
71 const Component
& path
,
77 // Given a spec and a pointer to the character after the colon following the
78 // scheme, this parses it and fills in the structure, Every item in the parsed
79 // structure is filled EXCEPT for the scheme, which is untouched.
80 void ParseAfterScheme(const char* spec
,
84 void ParseAfterScheme(const base::char16
* spec
,
91 #endif // URL_URL_PARSE_INTERNAL_H_