fixup Fix to build with libxml 2.12.x (fixes #505)
[platform/upstream/libzypp.git] / zypp / Pathname.cc
index 0dbb04e..d81a472 100644 (file)
@@ -11,9 +11,9 @@
 */
 #include <iostream>
 
-#include "zypp/base/String.h"
-#include "zypp/Pathname.h"
-#include "zypp/Url.h"
+#include <zypp/base/String.h>
+#include <zypp/Pathname.h>
+#include <zypp/Url.h>
 
 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