1 #pragma once
2 
3 #include <string>
4 
5 namespace mbgl {
6 
7 namespace util {
8 
9 std::string percentEncode(const std::string&);
10 std::string percentDecode(const std::string&);
11 
12 // Class that holds position + lenth pairs for scheme, domain, path + query string of a URL.
13 class URL {
14 public:
15     using Segment = std::pair<size_t, size_t>; // position, length
16 
17     const Segment query;
18     const Segment scheme;
19     const Segment domain;
20     const Segment path;
21 
22     URL(const std::string&);
23 };
24 
25 // Class that holds position + lenth pairs for directory, extension, and filename of a path.
26 // The extension will contain the preceding ., and optionally a preceding @2x specifier.
27 // The filename will not contain the file extension.
28 class Path {
29 public:
30     using Segment = std::pair<size_t, size_t>; // position, length
31 
32     const Segment directory;
33     const Segment extension;
34     const Segment filename;
35 
36     Path(const std::string&, size_t pos = 0, size_t count = std::string::npos);
37 };
38 
39 // Parses the given URL and replaces the tokens in template with parts of the URL.
40 // When parsing "http://example.com/foo/bar/baz.png", valid tokens are:
41 // * {scheme} == "http"
42 // * {domain} == "example.com"
43 // * {path} == "foo/bar/baz.png"
44 // * {directory} == "foo/bar/"
45 // * {filename} == "baz"
46 // * {extension} == ".png"
47 // The query string of the source URL will always be appended.
48 std::string transformURL(const std::string& tpl, const std::string& url, const URL&);
transformURL(const std::string & tpl,const std::string & url)49 inline std::string transformURL(const std::string& tpl, const std::string& url) {
50     return transformURL(tpl, url, URL(url));
51 }
52 
53 } // namespace util
54 } // namespace mbgl
55