libzypp: zypp::filesystem::Pathname Class Reference

libzypp 17.38.15

zypp::filesystem::Pathname Class Reference

Pathname. More...

`#include <zypp-core/Pathname.h>`

## Public Member Functions
| Pathname ()
| Default ctor: an empty path.
| Pathname (const std::string &name_r)
| Ctor from string.
| Pathname (const char *name_r)
| Ctor from char*.
| Pathname (const Pathname &rhs)
| Copy Ctor.
| Pathname (Pathname &&tmp) noexcept
| Move Ctor.
Pathname & | operator= (Pathname rhs)
| Assign.
Pathname & | operator/= (const Pathname &path_tv)
| Concatenate and assign.
Pathname & | operator+= (const Pathname &path_tv)
| Concatenate and assign.
const std::string & | asString () const
| String representation.
Url | asUrl (const std::string &scheme_r) const
| Url representation using `scheme_r` schema .
Url | asUrl () const
Url | asDirUrl () const
Url | asFileUrl () const
const char * | c_str () const
| String representation.
bool | empty () const
| Test for an empty path.
bool | absolute () const
| Test for an absolute path.
bool | relative () const
| Test for a relative path.
bool | relativeDotDot () const
| Test for a relative path referring to ../.
bool | emptyOrRoot () const
| Test for "" or "/".
bool | absoluteNotRoot () const
| Test for a not empty absolute Path (!= "/").
Pathname | dirname () const
| Return all but the last component od this path.
std::string | basename () const
| Return the last component of this path.
std::string | extension () const
| Return all of the characters in name after and including the last dot in the last element of name.
Pathname | absolutename () const
| Return this path, adding a leading '/' if relative.
Pathname | relativename () const
| Return this path, removing a leading '/' if absolute.
Pathname | realpath () const
| Returns this path as the absolute canonical pathname.
Pathname | cat (const Pathname &r) const
| Concatenation of pathnames.
Pathname | extend (const std::string &r) const
| Append string r to the last component of the path.

## Static Public Member Functions
static std::string | showRoot (const Pathname &root_r, const Pathname &path_r)
| String representation as "(root)/path".
static std::string | showRootIf (const Pathname &root_r, const Pathname &path_r)
| String representation as "(root)/path", unless root is `"/"` or empty.
static Pathname | dirname (const Pathname &name_r)
static std::string | basename (const Pathname &name_r)
static std::string | extension (const Pathname &name_r)
static Pathname | absolutename (const Pathname &name_r)
static Pathname | relativename (const Pathname &name_r)
static Pathname | assertprefix (const Pathname &root_r, const Pathname &path_r)
| Unless path_r does not already denote a path below root_r, combine them.
static Pathname | stripprefix (const Pathname &root_r, const Pathname &path_r)
| Return `path_r` with any `root_r` dir prefix striped.
static Pathname | cat (const Pathname &l, const Pathname &r)
static Pathname | extend (const Pathname &l, const std::string &r)

## Private Member Functions
void | _assign (const std::string &name_r)

## Private Attributes
std::string | _name

## Friends
void | swap (Pathname &lhs, Pathname &rhs) noexcept
| Swap.

## Detailed Description

Pathname.

Note
  For convenience Pathname is available as zypp::Pathname too.

Always stores normalized paths (no inner '.' or '..' components and no consecutive '/'es). Concatenation automatically adds the path separator '/'.

Todo
  Add support for handling extensions incl. stripping extensions from basename (basename("/path/foo.baa", ".baa") ==> "foo")

Definition at line 47 of file Pathname.h.

## Constructor & Destructor Documentation

## ◆ Pathname() [1/5]

zypp::filesystem::Pathname::Pathname | ( |  | ) |
| inline

Default ctor: an empty path.

Definition at line 51 of file Pathname.h.

## ◆ Pathname() [2/5]

zypp::filesystem::Pathname::Pathname | ( | const std::string & | name_r | ) |
| inline

Ctor from string.

Definition at line 55 of file Pathname.h.

## ◆ Pathname() [3/5]

zypp::filesystem::Pathname::Pathname | ( | const char * | name_r | ) |
| inline

Ctor from char*.

Definition at line 59 of file Pathname.h.

## ◆ Pathname() [4/5]

zypp::filesystem::Pathname::Pathname | ( | const Pathname & | rhs | ) |
| inline

Copy Ctor.

Definition at line 63 of file Pathname.h.

## ◆ Pathname() [5/5]

zypp::filesystem::Pathname::Pathname | ( | Pathname && | tmp | ) |
| inlinenoexcept

Move Ctor.

Definition at line 75 of file Pathname.h.

## Member Function Documentation

## ◆ operator=()

Pathname & zypp::filesystem::Pathname::operator= | ( | Pathname | rhs | ) |
| inline

Assign.

Definition at line 80 of file Pathname.h.

## ◆ operator/=()

Pathname & zypp::filesystem::Pathname::operator/= | ( | const Pathname & | path_tv | ) |
| inline

Concatenate and assign.

See also
  cat

Definition at line 84 of file Pathname.h.

## ◆ operator+=()

Pathname & zypp::filesystem::Pathname::operator+= | ( | const Pathname & | path_tv | ) |
| inline

Concatenate and assign.

See also
  cat

Deprecated
  : use /=

Definition at line 90 of file Pathname.h.

## ◆ asString()

const std::string & zypp::filesystem::Pathname::asString | ( |  | ) | const
| inline

String representation.

Definition at line 94 of file Pathname.h.

## ◆ showRoot()

std::string zypp::filesystem::Pathname::showRoot | ( | const Pathname & | root_r,
|  | const Pathname & | path_r )
| static

String representation as "(root)/path".

Definition at line 190 of file Pathname.cc.

## ◆ showRootIf()

std::string zypp::filesystem::Pathname::showRootIf | ( | const Pathname & | root_r,
|  | const Pathname & | path_r )
| static

String representation as "(root)/path", unless root is `"/"` or empty.

Definition at line 195 of file Pathname.cc.

## ◆ asUrl() [1/2]

Url zypp::filesystem::Pathname::asUrl | ( | const std::string & | scheme_r | ) | const

Url representation using `scheme_r` schema .

Definition at line 172 of file Pathname.cc.

## ◆ asUrl() [2/2]

Url zypp::filesystem::Pathname::asUrl | ( |  | ) | const

Definition at line 180 of file Pathname.cc.

## ◆ asDirUrl()

Url zypp::filesystem::Pathname::asDirUrl | ( |  | ) | const

Definition at line 183 of file Pathname.cc.

## ◆ asFileUrl()

Url zypp::filesystem::Pathname::asFileUrl | ( |  | ) | const

Definition at line 186 of file Pathname.cc.

## ◆ c_str()

const char * zypp::filesystem::Pathname::c_str | ( |  | ) | const
| inline

String representation.

Definition at line 113 of file Pathname.h.

## ◆ empty()

bool zypp::filesystem::Pathname::empty | ( |  | ) | const
| inline

Test for an empty path.

Definition at line 117 of file Pathname.h.

## ◆ absolute()

bool zypp::filesystem::Pathname::absolute | ( |  | ) | const
| inline

Test for an absolute path.

Definition at line 119 of file Pathname.h.

## ◆ relative()

bool zypp::filesystem::Pathname::relative | ( |  | ) | const
| inline

Test for a relative path.

Definition at line 121 of file Pathname.h.

## ◆ relativeDotDot()

bool zypp::filesystem::Pathname::relativeDotDot | ( |  | ) | const
| inline

Test for a relative path referring to ../.

Definition at line 124 of file Pathname.h.

## ◆ emptyOrRoot()

bool zypp::filesystem::Pathname::emptyOrRoot | ( |  | ) | const
| inline

Test for "" or "/".

Definition at line 127 of file Pathname.h.

## ◆ absoluteNotRoot()

bool zypp::filesystem::Pathname::absoluteNotRoot | ( |  | ) | const
| inline

Test for a not empty absolute Path (!= "/").

Definition at line 130 of file Pathname.h.

## ◆ dirname() [1/2]

Pathname zypp::filesystem::Pathname::dirname | ( |  | ) | const
| inline

Return all but the last component od this path.

Definition at line 133 of file Pathname.h.

## ◆ dirname() [2/2]

Pathname zypp::filesystem::Pathname::dirname | ( | const Pathname & | name_r | ) |
| static

Definition at line 129 of file Pathname.cc.

## ◆ basename() [1/2]

std::string zypp::filesystem::Pathname::basename | ( |  | ) | const
| inline

Return the last component of this path.

Definition at line 137 of file Pathname.h.

## ◆ basename() [2/2]

string zypp::filesystem::Pathname::basename | ( | const Pathname & | name_r | ) |
| static

Definition at line 153 of file Pathname.cc.

## ◆ extension() [1/2]

std::string zypp::filesystem::Pathname::extension | ( |  | ) | const
| inline

Return all of the characters in name after and including the last dot in the last element of name.

If there is no dot in the last element of name then returns the empty string.

Definition at line 144 of file Pathname.h.

## ◆ extension() [2/2]

string zypp::filesystem::Pathname::extension | ( | const Pathname & | name_r | ) |
| static

Definition at line 207 of file Pathname.cc.

## ◆ absolutename() [1/2]

Pathname zypp::filesystem::Pathname::absolutename | ( |  | ) | const
| inline

Return this path, adding a leading '/' if relative.

Definition at line 148 of file Pathname.h.

## ◆ absolutename() [2/2]

Pathname zypp::filesystem::Pathname::absolutename | ( | const Pathname & | name_r | ) |
| inlinestatic

Definition at line 149 of file Pathname.h.

## ◆ relativename() [1/2]

Pathname zypp::filesystem::Pathname::relativename | ( |  | ) | const
| inline

Return this path, removing a leading '/' if absolute.

Definition at line 153 of file Pathname.h.

## ◆ relativename() [2/2]

Pathname zypp::filesystem::Pathname::relativename | ( | const Pathname & | name_r | ) |
| inlinestatic

Definition at line 154 of file Pathname.h.

## ◆ realpath()

Pathname zypp::filesystem::Pathname::realpath | ( |  | ) | const

Returns this path as the absolute canonical pathname.

Definition at line 231 of file Pathname.cc.

## ◆ assertprefix()

Pathname zypp::filesystem::Pathname::assertprefix | ( | const Pathname & | root_r,
|  | const Pathname & | path_r )
| static

Unless path_r does not already denote a path below root_r, combine them.

It's asserted that a relative path_r referring to "../" does not escape root_r.

assertprefix( "/root", "/a" ) => "/root/a"
assertprefix( "/root", "a" ) => "/root/a"
assertprefix( "/root", "../a" ) => "/root/a"
assertprefix( "/root", "/root/a" ) => "/root/a"
assertprefix( "/root", "root/a" ) => "/root/root/a"
assertprefix( "/root", "/root/../a" ) => "/root/a"
zypp::filesystem::Pathname::assertprefix
static Pathname assertprefix(const Pathname &root_r, const Pathname &path_r)
Unless path_r does not already denote a path below root_r, combine them.
Definition Pathname.cc:272

Definition at line 272 of file Pathname.cc.

## ◆ stripprefix()

Pathname zypp::filesystem::Pathname::stripprefix | ( | const Pathname & | root_r,
|  | const Pathname & | path_r )
| static

Return `path_r` with any `root_r` dir prefix striped.

Definition at line 293 of file Pathname.cc.

## ◆ cat() [1/2]

Pathname zypp::filesystem::Pathname::cat | ( | const Pathname & | r | ) | const
| inline

Concatenation of pathnames.

"foo" / "baa" ==> "foo/baa"
"foo/" / "baa" ==> "foo/baa"
"foo" / "/baa" ==> "foo/baa"
"foo/" / "/baa" ==> "foo/baa"

Definition at line 184 of file Pathname.h.

## ◆ cat() [2/2]

Pathname zypp::filesystem::Pathname::cat | ( | const Pathname & | l,
|  | const Pathname & | r )
| static

Definition at line 310 of file Pathname.cc.

## ◆ extend() [1/2]

Pathname zypp::filesystem::Pathname::extend | ( | const std::string & | r | ) | const
| inline

Append string r to the last component of the path.

"foo/baa".extend( ".h" ) ==> "foo/baa.h"

Definition at line 192 of file Pathname.h.

## ◆ extend() [2/2]

Pathname zypp::filesystem::Pathname::extend | ( | const Pathname & | l,
|  | const std::string & | r )
| static

## ◆ _assign()

void zypp::filesystem::Pathname::_assign | ( | const std::string & | name_r | ) |
| private

Definition at line 33 of file Pathname.cc.

## Friends And Related Symbol Documentation

## ◆ swap

void swap | ( | Pathname & | lhs,
|  | Pathname & | rhs )
| friend

Swap.

Definition at line 68 of file Pathname.h.

## Member Data Documentation

## ◆ _name

std::string zypp::filesystem::Pathname::_name
| private

Definition at line 196 of file Pathname.h.

The documentation for this class was generated from the following files:

- zypp-core/Pathname.h
- zypp-core/Pathname.cc