| 941 | // lexical operations --------------------------------------------------------------// |
| 942 | |
| 943 | BOOST_FILESYSTEM_DECL path path::lexically_relative(path const& base) const |
| 944 | { |
| 945 | path::iterator b = begin(), e = end(), base_b = base.begin(), base_e = base.end(); |
| 946 | std::pair< path::iterator, path::iterator > mm = detail::mismatch(b, e, base_b, base_e); |
| 947 | if (mm.first == b && mm.second == base_b) |
| 948 | return path(); |
| 949 | if (mm.first == e && mm.second == base_e) |
| 950 | return detail::dot_path(); |
| 951 | |
| 952 | std::ptrdiff_t n = 0; |
| 953 | for (; mm.second != base_e; detail::path_algorithms::increment_v4(mm.second)) |
| 954 | { |
| 955 | path const& p = *mm.second; |
| 956 | if (detail::path_algorithms::compare_v4(p, detail::dot_dot_path()) == 0) |
| 957 | --n; |
| 958 | else if (!p.empty() && detail::path_algorithms::compare_v4(p, detail::dot_path()) != 0) |
| 959 | ++n; |
| 960 | } |
| 961 | if (n < 0) |
| 962 | return path(); |
| 963 | if (n == 0 && (mm.first == e || mm.first->empty())) |
| 964 | return detail::dot_path(); |
| 965 | |
| 966 | path tmp; |
| 967 | for (; n > 0; --n) |
| 968 | detail::path_algorithms::append_v4(tmp, detail::dot_dot_path()); |
| 969 | for (; mm.first != e; detail::path_algorithms::increment_v4(mm.first)) |
| 970 | detail::path_algorithms::append_v4(tmp, *mm.first); |
| 971 | return tmp; |
| 972 | } |
| 973 | |
| 974 | } // namespace filesystem |
| 975 | } // namespace boost |