X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=zypp%2FPathname.cc;h=61b08afb01d2ca898a5b2910416e4899758f9cf7;hb=HEAD;hp=0dbb04e56d0899e1eebe7cd91129a44e5d4d2b23;hpb=42b5d038414cf4a4a050e816b471f890b24e8032;p=platform%2Fupstream%2Flibzypp.git diff --git a/zypp/Pathname.cc b/zypp/Pathname.cc index 0dbb04e..d81a472 100644 --- a/zypp/Pathname.cc +++ b/zypp/Pathname.cc @@ -11,9 +11,9 @@ */ #include -#include "zypp/base/String.h" -#include "zypp/Pathname.h" -#include "zypp/Url.h" +#include +#include +#include using std::string; @@ -131,9 +131,9 @@ namespace zypp return Pathname(); Pathname ret_t( name_r ); - string::size_type idx = ret_t._name.find_last_of( '/' ); + std::string::size_type idx = ret_t._name.find_last_of( '/' ); - if ( idx == string::npos ) { + if ( idx == std::string::npos ) { ret_t._name = "."; } else if ( idx == 0 ) { ret_t._name = "/"; @@ -155,8 +155,8 @@ namespace zypp return string(); string ret_t( name_r.asString() ); - string::size_type idx = ret_t.find_last_of( '/' ); - if ( idx != string::npos && ( idx != 0 || ret_t.size() != 1 ) ) { + std::string::size_type idx = ret_t.find_last_of( '/' ); + if ( idx != std::string::npos && ( idx != 0 || ret_t.size() != 1 ) ) { ret_t.erase( 0, idx+1 ); } @@ -209,7 +209,7 @@ namespace zypp return string(); string base( basename( name_r ) ); - string::size_type pos = base.rfind( '.' ); + std::string::size_type pos = base.rfind( '.' ); switch ( pos ) { case 0: @@ -220,7 +220,7 @@ namespace zypp if ( base.size() == 2 && base[0] == '.' ) // .. return string(); break; - case string::npos: + case std::string::npos: return string(); break; } @@ -241,6 +241,18 @@ namespace zypp return root_r / path_r; } + Pathname Pathname::stripprefix( const Pathname & root_r, const Pathname & path_r ) + { + if ( root_r.emptyOrRoot() ) + return path_r; + if ( root_r == path_r ) + return "/"; + std::string rest( str::stripPrefix( path_r.asString(), root_r.asString() ) ); + if ( rest[0] == '/' ) // needs to be a dir prefix! + return rest; + return path_r; + } + /////////////////////////////////////////////////////////////////// // // METHOD NAME : Pathname::cat