Added Pathname::showRoot/showRootIf: pretty print pathnames with optional root prefix.
authorMichael Andres <ma@suse.de>
Fri, 9 Oct 2009 11:47:31 +0000 (13:47 +0200)
committerMichael Andres <ma@suse.de>
Fri, 9 Oct 2009 11:47:31 +0000 (13:47 +0200)
zypp/Pathname.cc
zypp/Pathname.h

index 76e53f8..1b41a89 100644 (file)
@@ -241,6 +241,18 @@ namespace zypp
       return ret;
     }
 
+    std::string Pathname::showRoot( const Pathname & root_r, const Pathname & path_r )
+    {
+      return str::Str() << "(" << root_r << ")" << path_r;
+    }
+
+    std::string Pathname::showRootIf( const Pathname & root_r, const Pathname & path_r )
+    {
+      if ( root_r.empty() || root_r == "/" )
+        return path_r.asString();
+      return showRoot( root_r, path_r );
+    }
+
     ///////////////////////////////////////////////////////////////////
     //
     // METHOD NAME : Pathname::extension
index 0632536..a93c4b3 100644 (file)
@@ -80,6 +80,12 @@ namespace zypp
       const std::string & asString() const
       { return name_t; }
 
+      /** String representation as "(root)/path" */
+      static std::string showRoot( const Pathname & root_r, const Pathname & path_r );
+
+      /** String representation as "(root)/path", unless \a root is \c "/" or empty. */
+      static std::string showRootIf( const Pathname & root_r, const Pathname & path_r );
+
       /** Url representation using \c dir schema. */
       Url asUrl() const;