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:
24  Directive(std::string_view from, std::string_view to, int status);
25  std::uint16_t rewrite(std::string&) const;
26  std::string error() const;
27  bool valid() const { return error().empty(); }
28 };
31 class File {
32  std::vector<Directive> directives_;
33  std::string error_;
34 
35  public:
36  explicit File(std::string_view to_parse);
37 
38  bool valid() const { return error().empty(); }
39  std::string const& error() const { return error_; }
40  std::uint16_t rewrite(std::string& missing_path) const;
41 
42  private:
43  bool parse_line(std::string_view, int);
44 };
45 } // namespace ipfs::redirects
46 
47 #endif // IPFS_REDIRECTS_H_
Definition: redirects.h:13
Directive(std::string_view from, std::string_view to, int status)
Definition: redirects.h:31