Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-31 10:12:00

0001 // Protocol Buffers - Google's data interchange format
0002 // Copyright 2023 Google LLC.  All rights reserved.
0003 //
0004 // Use of this source code is governed by a BSD-style
0005 // license that can be found in the LICENSE file or at
0006 // https://developers.google.com/open-source/licenses/bsd
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 // Relative path using '/' as a separator.
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     // `..` and `.` not supported, since there's no use case for that right now.
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   // Returns a path getting us from the current relative path to the `dest`
0038   // path.
0039   //
0040   // Supports both files and directories.
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 }  // namespace rust
0050 }  // namespace compiler
0051 }  // namespace protobuf
0052 }  // namespace google
0053 
0054 #endif  // GOOGLE_PROTOBUF_COMPILER_RUST_RELATIVE_PATH_H__