| 113 | } |
| 114 | |
| 115 | std::string Path::Encode(fs::path const& path) const { |
| 116 | // Find the shortest encoding of path made relative to each token |
| 117 | std::string shortest = path.string(); |
| 118 | size_t length = boost::distance(path); |
| 119 | for (size_t i = 0; i < paths.size(); ++i) { |
| 120 | if (paths[i].empty()) continue; |
| 121 | |
| 122 | const auto p = MakeRelative(path, tokens[i]); |
| 123 | const size_t d = boost::distance(p); |
| 124 | if (d < length) { |
| 125 | length = d; |
| 126 | shortest = (tokens[i]/p).string(); |
| 127 | } |
| 128 | } |
| 129 | |
| 130 | return shortest; |
| 131 | } |
| 132 | |
| 133 | void Path::SetToken(std::string_view token_name, fs::path const& token_value) { |
| 134 | int idx = checked_find_token(token_name); |