1 // Copyright 2020 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.
4 
5 #ifndef THIRD_PARTY_MOZILLA_URL_PARSE_INTERNAL_H_
6 #define THIRD_PARTY_MOZILLA_URL_PARSE_INTERNAL_H_
7 
8 namespace openscreen {
9 
10 struct Component;
11 
12 static constexpr char kHttpsScheme[] = "https";
13 static constexpr char kHttpScheme[] = "http";
14 static constexpr char kFileScheme[] = "file";
15 static constexpr char kFtpScheme[] = "ftp";
16 static constexpr char kWssScheme[] = "wss";
17 static constexpr char kWsScheme[] = "ws";
18 static constexpr char kFileSystemScheme[] = "filesystem";
19 static constexpr char kMailtoScheme[] = "mailto";
20 
21 // Returns whether the character |ch| should be treated as a slash.
22 bool IsURLSlash(char ch);
23 
24 // Returns whether the character |ch| can be safely removed for the URL.
25 bool ShouldTrimFromURL(char ch);
26 
27 // Given an already-initialized begin index and length, this shrinks the range
28 // to eliminate "should-be-trimmed" characters. Note that the length does *not*
29 // indicate the length of untrimmed data from |*begin|, but rather the position
30 // in the input string (so the string starts at character |*begin| in the spec,
31 // and goes until |*len|).
32 void TrimURL(const char* spec, int* begin, int* len, bool trim_path_end = true);
33 
34 // Returns the number of consecutive slashes in |str| starting from offset
35 // |begin_offset|.
36 int CountConsecutiveSlashes(const char* str, int begin_offset, int str_len);
37 
38 // Given a string and a range inside the string, compares it to the given
39 // lower-case |compare_to| buffer.
40 bool CompareSchemeComponent(const char* spec,
41                             const Component& component,
42                             const char* compare_to);
43 
44 // Returns whether the scheme given by (spec, component) is a standard scheme
45 // (i.e. https://url.spec.whatwg.org/#special-scheme).
46 bool IsStandard(const char* spec, const Component& component);
47 
48 }  // namespace openscreen
49 
50 #endif  // THIRD_PARTY_MOZILLA_URL_PARSE_INTERNAL_H_
51