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_FILE_H_
6 #define URL_URL_FILE_H_
8 // Provides shared functions used by the internals of the parser and
9 // canonicalizer for file URLs. Do not use outside of these modules.
11 #include "base/strings/string_util.h"
12 #include "url/url_parse_internal.h"
18 // We allow both "c:" and "c|" as drive identifiers.
19 inline bool IsWindowsDriveSeparator(base::char16 ch) {
20 return ch == ':' || ch == '|';
25 // Returns the index of the next slash in the input after the given index, or
26 // spec_len if the end of the input is reached.
27 template<typename CHAR>
28 inline int FindNextSlash(const CHAR* spec, int begin_index, int spec_len) {
29 int idx = begin_index;
30 while (idx < spec_len && !IsURLSlash(spec[idx]))
37 // Returns true if the start_offset in the given spec looks like it begins a
38 // drive spec, for example "c:". This function explicitly handles start_offset
39 // values that are equal to or larger than the spec_len to simplify callers.
41 // If this returns true, the spec is guaranteed to have a valid drive letter
42 // plus a colon starting at |start_offset|.
43 template<typename CHAR>
44 inline bool DoesBeginWindowsDriveSpec(const CHAR* spec, int start_offset,
46 int remaining_len = spec_len - start_offset;
47 if (remaining_len < 2)
48 return false; // Not enough room.
49 if (!base::IsAsciiAlpha(spec[start_offset]))
50 return false; // Doesn't start with a valid drive letter.
51 if (!IsWindowsDriveSeparator(spec[start_offset + 1]))
52 return false; // Isn't followed with a drive separator.
56 // Returns true if the start_offset in the given text looks like it begins a
57 // UNC path, for example "\\". This function explicitly handles start_offset
58 // values that are equal to or larger than the spec_len to simplify callers.
60 // When strict_slashes is set, this function will only accept backslashes as is
61 // standard for Windows. Otherwise, it will accept forward slashes as well
62 // which we use for a lot of URL handling.
63 template<typename CHAR>
64 inline bool DoesBeginUNCPath(const CHAR* text,
67 bool strict_slashes) {
68 int remaining_len = len - start_offset;
69 if (remaining_len < 2)
73 return text[start_offset] == '\\' && text[start_offset + 1] == '\\';
74 return IsURLSlash(text[start_offset]) && IsURLSlash(text[start_offset + 1]);
81 #endif // URL_URL_FILE_H_