File indexing completed on 2025-01-31 10:12:00
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef GOOGLE_PROTOBUF_COMPILER_RUST_RELATIVE_PATH_H__
0009 #define GOOGLE_PROTOBUF_COMPILER_RUST_RELATIVE_PATH_H__
0010
0011 #include <string>
0012 #include <vector>
0013
0014 #include "absl/algorithm/container.h"
0015 #include "absl/log/absl_check.h"
0016 #include "absl/strings/match.h"
0017 #include "absl/strings/string_view.h"
0018
0019 namespace google {
0020 namespace protobuf {
0021 namespace compiler {
0022 namespace rust {
0023
0024
0025 class RelativePath final {
0026 public:
0027 explicit RelativePath(absl::string_view path) : path_(path) {
0028 ABSL_CHECK(!absl::StartsWith(path, "/"))
0029 << "only relative paths are supported";
0030
0031 for (absl::string_view segment : Segments()) {
0032 ABSL_CHECK(segment != "..") << "`..` segments are not supported";
0033 ABSL_CHECK(segment != ".") << "`.` segments are not supported";
0034 }
0035 }
0036
0037
0038
0039
0040
0041 std::string Relative(const RelativePath& dest) const;
0042 std::vector<absl::string_view> Segments() const;
0043 bool IsDirectory() const;
0044
0045 private:
0046 absl::string_view path_;
0047 };
0048
0049 }
0050 }
0051 }
0052 }
0053
0054 #endif