nx_storage_sdk  1.0
Storage SDK
url.h
1 // Copyright 2018-present Network Optix, Inc. Licensed under MPL 2.0: www.mozilla.org/MPL/2.0/
2 
3 #pragma once
4 
5 #include <algorithm>
6 #include <cstring>
7 #include <memory>
8 #include <string>
9 #include <unordered_map>
10 
11 #include <common.h>
12 
13 namespace utils {
14 
15 using ParamsMap = std::unordered_map<std::string, std::string>;
16 
17 class NX_PLUGIN_API Url
18 {
19  enum class ParseState
20  {
21  scheme,
22  hostPath,
23  params,
24  nextParam,
25  error,
26  ok
27  };
28 
29 public:
30  Url(const std::string& url);
31 
32  std::string scheme() const;
33  std::string url() const;
34  std::string hostPath() const;
35  std::string host() const;
36  std::string path() const;
37 
38  ParamsMap params() const;
39  bool valid() const;
40 
41 private:
42  void parse();
43  ParseState parseSome();
44  ParseState parseScheme();
45  ParseState parseHostPath();
46  ParseState parseParams();
47  ParseState parseParam();
48 
49  void copyAndAdvance(std::string* target, size_t endIndex);
50  ParseState checkAndAdvance(const std::string& stringToCheck, ParseState nextState);
51 
52 private:
53  const std::string& m_url;
54  std::string m_scheme;
55  std::string m_host;
56  std::string m_path;
57  ParamsMap m_params;
58  size_t m_index;
59  ParseState m_state;
60 };
61 
62 }
Definition: url.h:17
Definition: url.cpp:6