xref: /aosp_15_r20/external/cronet/net/third_party/quiche/src/quiche/common/platform/api/quiche_url_utils.h (revision 6777b5387eb2ff775bb5750e3f5d96f37fb7352b)
1 // Copyright 2021 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 QUICHE_COMMON_PLATFORM_API_QUICHE_URL_UTILS_H_
6 #define QUICHE_COMMON_PLATFORM_API_QUICHE_URL_UTILS_H_
7 
8 #include <optional>
9 #include <string>
10 
11 #include "absl/container/flat_hash_map.h"
12 #include "absl/container/flat_hash_set.h"
13 #include "absl/strings/string_view.h"
14 
15 #include "quiche_platform_impl/quiche_url_utils_impl.h"
16 
17 namespace quiche {
18 
19 // Produces concrete URLs in |target| from templated ones in |uri_template|.
20 // Parameters are URL-encoded. Collects the names of any expanded variables in
21 // |vars_found|. Returns true if the template was parseable, false if it was
22 // malformed.
23 inline bool ExpandURITemplate(
24     const std::string& uri_template,
25     const absl::flat_hash_map<std::string, std::string>& parameters,
26     std::string* target,
27     absl::flat_hash_set<std::string>* vars_found = nullptr) {
28   return ExpandURITemplateImpl(uri_template, parameters, target, vars_found);
29 }
30 
31 // Decodes a URL-encoded string and converts it to ASCII. If the decoded input
32 // contains non-ASCII characters, decoding fails and std::nullopt is returned.
AsciiUrlDecode(absl::string_view input)33 inline std::optional<std::string> AsciiUrlDecode(absl::string_view input) {
34   return AsciiUrlDecodeImpl(input);
35 }
36 
37 }  // namespace quiche
38 
39 #endif  // QUICHE_COMMON_PLATFORM_API_QUICHE_URL_UTILS_H_
40