From 987f61e077b3706e04d6064143a753e4e6e438ac Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 9 Oct 2009 13:47:31 +0200 Subject: [PATCH] Added Pathname::showRoot/showRootIf: pretty print pathnames with optional root prefix. --- zypp/Pathname.cc | 12 ++++++++++++ zypp/Pathname.h | 6 ++++++ 2 files changed, 18 insertions(+) diff --git a/zypp/Pathname.cc b/zypp/Pathname.cc index 76e53f8..1b41a89 100644 --- a/zypp/Pathname.cc +++ b/zypp/Pathname.cc @@ -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 diff --git a/zypp/Pathname.h b/zypp/Pathname.h index 0632536..a93c4b3 100644 --- a/zypp/Pathname.h +++ b/zypp/Pathname.h @@ -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; -- 2.7.4