MCPcopy Create free account
hub / github.com/boostorg/filesystem / absolute

Function absolute

src/operations.cpp:707–760  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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
762namespace detail
763{

Callers 3

absolute_testsFunction · 0.85
canonicalFunction · 0.85
completeFunction · 0.85

Calls 3

root_nameMethod · 0.80
root_directoryMethod · 0.80
relative_pathMethod · 0.80

Tested by 1

absolute_testsFunction · 0.68