15#include <zypp-core/base/String.h>
16#include <zypp-core/Pathname.h>
17#include <zypp-core/Url.h>
38 _name.reserve( name_r.size() );
50 if ( name_r[0] !=
'/' )
62 auto goParent_f = [&](){
65 else if (
_name.size() == 1 )
69 std::string::size_type pos =
_name.rfind(
"/" );
70 if ( pos ==
_name.size() - 3 &&
_name[pos+1] ==
'.' &&
_name[pos+2] ==
'.' )
77 for (
char ch : name_r )
84 case P_none: pending = P_slash;
break;
86 case P_dot1: pending = P_slash;
break;
87 case P_dot2: goParent_f(); pending = P_slash;
break;
94 case P_none:
_name +=
'.';
break;
95 case P_slash: pending = P_dot1;
break;
96 case P_dot1: pending = P_dot2;
break;
97 case P_dot2:
_name +=
"/..."; pending = P_none;
break;
105 case P_slash:
_name +=
'/'; pending = P_none;
break;
106 case P_dot1:
_name +=
"/."; pending = P_none;
break;
107 case P_dot2:
_name +=
"/.."; pending = P_none;
break;
117 case P_slash:
if (
_name.empty() )
_name =
"/";
break;
118 case P_dot1:
if (
_name.empty() )
_name =
"/";
break;
119 case P_dot2: goParent_f();
if (
_name.empty() )
_name =
"/";
break;
131 if ( name_r.
empty() )
135 std::string::size_type idx = ret_t.
_name.find_last_of(
'/' );
137 if ( idx == std::string::npos ) {
139 }
else if ( idx == 0 ) {
142 ret_t.
_name.erase( idx );
155 if ( name_r.
empty() )
159 std::string::size_type idx = ret_t.find_last_of(
'/' );
160 if ( idx != std::string::npos && ( idx != 0 || ret_t.size() != 1 ) ) {
161 ret_t.erase( 0, idx+1 );
181 {
return asUrl(
"dir" ); }
184 {
return asUrl(
"dir" ); }
187 {
return asUrl(
"file" ); }
192 return str::Str() <<
"(" << root_r <<
")" << path_r;
197 if ( root_r.
empty() || root_r ==
"/" )
209 if ( name_r.
empty() )
213 std::string::size_type pos = base.rfind(
'.' );
217 if ( base.size() == 1 )
221 if ( base.size() == 2 && base[0] ==
'.' )
224 case std::string::npos:
228 return base.substr( pos );
248 char buff[PATH_MAX + 2];
249 memset(buff,
'\0',
sizeof(buff));
256 char buff[PATH_MAX + 2];
257 memset(buff,
'\0',
sizeof(buff));
278 return root_r / path_r;
285 if ( root_r == path_r )
288 if ( rest[0] ==
'/' )
300 if ( add_tv.
empty() )
302 if ( name_r.
empty() )
305 string ret_ti( name_r.
_name );
306 if( add_tv.
_name[0] !=
'/' )
308 return ret_ti + add_tv.
_name;
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
static std::string showRoot(const Pathname &root_r, const Pathname &path_r)
String representation as "(root)/path".
Pathname extend(const std::string &r) const
Append string r to the last component of the path.
static Pathname stripprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r with any root_r dir prefix striped.
Pathname dirname() const
Return all but the last component od this path.
bool emptyOrRoot() const
Test for "" or "/".
Pathname cat(const Pathname &r) const
Concatenation of pathnames.
Pathname()
Default ctor: an empty path.
const std::string & asString() const
String representation.
std::string basename() const
Return the last component of this path.
bool empty() const
Test for an empty path.
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
void _assign(const std::string &name_r)
Pathname realpath() const
Returns this path as the absolute canonical pathname.
static std::string showRootIf(const Pathname &root_r, const Pathname &path_r)
String representation as "(root)/path", unless root is "/" or empty.
std::string extension() const
Return all of the characters in name after and including the last dot in the last element of name.
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
std::string stripPrefix(const C_Str &str_r, const C_Str &prefix_r)
Strip a prefix_r from str_r and return the resulting string.
Easy-to use interface to the ZYPP dependency resolver.
Convenient building of std::string via std::ostringstream Basically a std::ostringstream autoconverti...