| 705 | { |
| 706 | |
| 707 | BOOST_FILESYSTEM_DECL |
| 708 | path absolute(const path& p, const path& base) |
| 709 | { |
| 710 | // if ( p.empty() || p.is_absolute() ) |
| 711 | // return p; |
| 712 | // // recursively calling absolute is sub-optimal, but is simple |
| 713 | // path abs_base(base.is_absolute() ? base : absolute(base)); |
| 714 | //# ifdef BOOST_WINDOWS_API |
| 715 | // if (p.has_root_directory()) |
| 716 | // return abs_base.root_name() / p; |
| 717 | // // !p.has_root_directory |
| 718 | // if (p.has_root_name()) |
| 719 | // return p.root_name() |
| 720 | // / abs_base.root_directory() / abs_base.relative_path() / p.relative_path(); |
| 721 | // // !p.has_root_name() |
| 722 | //# endif |
| 723 | // return abs_base / p; |
| 724 | |
| 725 | // recursively calling absolute is sub-optimal, but is sure and simple |
| 726 | path abs_base(base.is_absolute() ? base : absolute(base)); |
| 727 | |
| 728 | // store expensive to compute values that are needed multiple times |
| 729 | path p_root_name (p.root_name()); |
| 730 | path base_root_name (abs_base.root_name()); |
| 731 | path p_root_directory (p.root_directory()); |
| 732 | |
| 733 | if (p.empty()) |
| 734 | return abs_base; |
| 735 | |
| 736 | if (!p_root_name.empty()) // p.has_root_name() |
| 737 | { |
| 738 | if (p_root_directory.empty()) // !p.has_root_directory() |
| 739 | return p_root_name / abs_base.root_directory() |
| 740 | / abs_base.relative_path() / p.relative_path(); |
| 741 | // p is absolute, so fall through to return p at end of block |
| 742 | } |
| 743 | |
| 744 | else if (!p_root_directory.empty()) // p.has_root_directory() |
| 745 | { |
| 746 | # ifdef BOOST_POSIX_API |
| 747 | // POSIX can have root name it it is a network path |
| 748 | if (base_root_name.empty()) // !abs_base.has_root_name() |
| 749 | return p; |
| 750 | # endif |
| 751 | return base_root_name / p; |
| 752 | } |
| 753 | |
| 754 | else |
| 755 | { |
| 756 | return abs_base / p; |
| 757 | } |
| 758 | |
| 759 | return p; // p.is_absolute() is true |
| 760 | } |
| 761 | |
| 762 | namespace detail |
| 763 | { |