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