37 _name.reserve( name_r.size() );
49 if ( name_r[0] !=
'/' )
61 auto goParent_f = [&](){
64 else if (
_name.size() == 1 )
69 if ( pos ==
_name.size() - 3 &&
_name[pos+1] ==
'.' &&
_name[pos+2] ==
'.' )
76 for (
auto ch : name_r )
83 case P_none: pending = P_slash;
break;
85 case P_dot1: pending = P_slash;
break;
86 case P_dot2: goParent_f(); pending = P_slash;
break;
93 case P_none:
_name +=
'.';
break;
94 case P_slash: pending = P_dot1;
break;
95 case P_dot1: pending = P_dot2;
break;
96 case P_dot2:
_name +=
"/..."; pending = P_none;
break;
104 case P_slash:
_name +=
'/'; pending = P_none;
break;
105 case P_dot1:
_name +=
"/."; pending = P_none;
break;
106 case P_dot2:
_name +=
"/.."; pending = P_none;
break;
116 case P_slash:
if (
_name.empty() )
_name =
"/";
break;
117 case P_dot1:
if (
_name.empty() )
_name =
"/";
break;
118 case P_dot2: goParent_f();
if (
_name.empty() )
_name =
"/";
break;
130 if ( name_r.
empty() )
136 if ( idx == string::npos ) {
138 }
else if ( idx == 0 ) {
141 ret_t.
_name.erase( idx );
154 if ( name_r.
empty() )
159 if ( idx != string::npos && ( idx != 0 || ret_t.size() != 1 ) ) {
160 ret_t.erase( 0, idx+1 );
180 {
return asUrl(
"dir" ); }
183 {
return asUrl(
"dir" ); }
186 {
return asUrl(
"file" ); }
191 return str::Str() <<
"(" << root_r <<
")" << path_r;
196 if ( root_r.
empty() || root_r ==
"/" )
208 if ( name_r.
empty() )
216 if ( base.size() == 1 )
220 if ( base.size() == 2 && base[0] ==
'.' )
227 return base.substr( pos );
241 return root_r / path_r;
251 if ( add_tv.
empty() )
253 if ( name_r.
empty() )
256 string ret_ti( name_r.
_name );
257 if( add_tv.
_name[0] !=
'/' )
259 return ret_ti + add_tv.
_name;
std::string basename() const
Return the last component of this path.
bool empty() const
Test for an empty path.
const std::string & asString() const
String representation.
static std::string showRootIf(const Pathname &root_r, const Pathname &path_r)
String representation as "(root)/path", unless root is "/" or empty.
Pathname dirname() const
Return all but the last component od this path.
void setPathName(const std::string &path, EEncoding eflag=zypp::url::E_DECODED)
Set the path name.
Convenient building of std::string via std::ostream::operator<<.
void setScheme(const std::string &scheme)
Set the scheme name in the URL.
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Return path_r prefixed with root_r, unless it is already prefixed.
Pathname()
Default ctor: an empty path.
std::string extension() const
Return all of the characters in name after and including the last dot in the last element of name...
static std::string showRoot(const Pathname &root_r, const Pathname &path_r)
String representation as "(root)/path".
Pathname cat(const Pathname &r) const
Concatenation of pathnames.
void _assign(const std::string &name_r)
bool hasPrefix(const C_Str &str_r, const C_Str &prefix_r)
Return whether str_r has prefix prefix_r.
Pathname extend(const std::string &r) const
Append string r to the last component of the path.