ipfs-chromium
redirects.h
1 #ifndef IPFS_REDIRECTS_H_
2 #define IPFS_REDIRECTS_H_
3 
4 #include <cstdint>
5 
6 #include <string>
7 #include <string_view>
8 #include <vector>
9 
10 namespace ipfs ::redirects {
13 class Directive {
14  enum class ComponentType { LITERAL, PLACEHOLDER, SPLAT };
15  std::vector<std::pair<ComponentType, std::string>> components_;
16  std::string to_;
17  int const status_;
18 
19  public:
20  Directive(std::string_view, std::string_view, int);
21  std::uint16_t rewrite(std::string&) const;
22  std::string error() const;
23  bool valid() const { return error().empty(); }
24 };
27 class File {
28  std::vector<Directive> directives_;
29  std::string error_;
30 
31  public:
32  explicit File(std::string_view to_parse);
33 
34  bool valid() const { return error().empty(); }
35  std::string const& error() const { return error_; }
36  std::uint16_t rewrite(std::string& missing_path) const;
37 
38  private:
39  bool parse_line(std::string_view, int);
40 };
41 } // namespace ipfs::redirects
42 
43 #endif // IPFS_REDIRECTS_H_
Definition: redirects.h:13
Definition: redirects.h:27