Lumino
ln::Path Class Reference

ファイルパス文字列を表すクラスです。 More...

#include <Path.hpp>

Public Member Functions

 Path (const Char *path)
 指定されたパス文字列から Path を構築します。
 
 Path (const String &path)
 指定されたパス文字列から Path を構築します。
 
 Path (const StringRef &path)
 指定されたパス文字列から Path を構築します。
 
 Path (const Path &basePath, const Char *relativePath)
 指定されたパス文字列を連結して Path を構築します。relativePath が絶対パスである場合、basePath は無視されます。
 
bool isEmpty () const
 パスが空であるかを確認します。
 
int length () const
 パス文字列の長さを返します。
 
const Char * c_str () const
 C言語形式の文字列ポインタを返します。
 
const Stringstr () const
 パス文字列を String として返します。
 
bool isAbsolute () const
 このパスが絶対パスであるかを確認します。
 
bool isRelative () const
 このパスが相対パスであるかを確認します。
 
bool isRoot () const
 このパスがルートパスであるかを確認します。
 
bool isUnified () const
 セパレータがすべて '/' であるかを確認します。
 
bool hasExtension (const StringRef &ext=StringRef()) const
 このパスが指定された拡張子を持っているかを確認します。 (ext の . More...
 
Path fileName () const
 パス文字列の中から拡張子を含むファイル名の部分を返します。

"dir/file.txt" => "file.txt"
"file.txt" => "file.txt"
"file" => "file"
"dir/.git" => "dir/.git"
"." => "."

 
Path withoutExtension () const
 このパスから拡張子を取り除いたパスを返します。

"/dir/file.txt" => "/dir/file"
"file.txt" => "file"
"file" => "file"
"C:/dir.sub/file" => "C:/dir.sub/file"
"dir/.git" => "dir/"
".git" => ""
"" => ""

 
StringRef fileNameWithoutExtension () const
 パス文字列の中から拡張子を含まないファイル名の部分を返します。

"dir/file.txt" => "file"
"file.txt" => "file"
"dir/.file" => ""
".file" => ""

 
StringRef extension (bool withDot=true) const
 ファイルの拡張子を取得します。 More...
 
Path parent () const
 親ディレクトリのパスを取得します。

"dir1/file1.txt" => "dir1"
"dir" => ""
"dir/" => "dir"
"/" => "/"
"C:" => "C:"
"" => ".."
".." => "../.."
"." => ""

 
Path native () const
 セパレータをネイティブの文字に変換したパスを返します。
 
Path unify () const
 セパレータを '/' に変換したパスを返します。
 
Path canonicalize () const
 パスを単純化し、絶対パスにしたものを返します。 More...
 
Path makeRelative (const Path &target) const
 このパスから指定したパスへの相対パスを取得します。 More...
 
Path replaceExtension (const StringRef &newExt) const
 このパスの拡張子を変更した新しいパスを返します。 More...
 
Path withEndSeparator () const
 末尾にひとつのセパレータがあるようにした新しいパスを返します。
 
void clear ()
 パス文字列をクリアします。
 
void append (const StringRef &path)
 現在のパスに別のパス文字列を連結します。 More...
 

Static Public Member Functions

static int compare (const StringRef &path1, const StringRef &path2)
 このパスと別のパス文字列が等しいかを確認します。 More...
 
static Path getSpecialFolderPath (SpecialFolder specialFolder, const StringRef &relativeDirPath=StringRef(), SpecialFolderOption option=SpecialFolderOption::Create)
 システムの特別なフォルダのパスを取得します。
 
static Path getUniqueFilePathInDirectory (const Path &directory, const Char *filePrefix, const Char *extName)
 フォルダ内でユニークなファイルパス(絶対パス)を生成して返す More...
 

Detailed Description

ファイルパス文字列を表すクラスです。

このクラスはセパレータで区切られた文字列をラップして操作します。

セパレータは環境依存です。例えば、Windows では '\'、UNIX 系では '/' です。 入力された文字列に含まれるセパレータは元の文字を維持します。 セパレータをネイティブの文字に変換する場合は native() を使用します。

このクラスに含まれる比較機能は、動作中のファイルシステムによって大文字小文字の区別を決定します。

Member Function Documentation

◆ append()

void ln::Path::append ( const StringRef path)

現在のパスに別のパス文字列を連結します。

Parameters
[in]path: パス文字列 現在のパスの末尾にセパレータが無い場合は付加し、文字列を連結します。path が絶対パスであれば、現在のパスを置き換えます。

◆ canonicalize()

Path ln::Path::canonicalize ( ) const

パスを単純化し、絶対パスにしたものを返します。

パスが相対パスの場合はカレントディレクトリを基準にして絶対パスを求めます。 また、セパレータをネイティブの文字に変換されます。

◆ compare()

static int ln::Path::compare ( const StringRef path1,
const StringRef path2 
)
static

このパスと別のパス文字列が等しいかを確認します。

字句表現としての等価性を評価します。2つのパスが同一のファイルシステムオブジェクトを指すかは確認しません。 環境により、ディレクトリセパレータ ('/' と '\') や大文字小文字を同一視します。

◆ extension()

StringRef ln::Path::extension ( bool  withDot = true) const

ファイルの拡張子を取得します。

Parameters
[in]withDot: true の場合、結果は '.' を含み、false の場合は含まない
"file.txt" => ".txt"
"file.tmp.txt" => ".txt"
"file" => ""
".file" => ".file"
"." => ""
"" => ""

◆ getUniqueFilePathInDirectory()

static Path ln::Path::getUniqueFilePathInDirectory ( const Path directory,
const Char *  filePrefix,
const Char *  extName 
)
static

フォルダ内でユニークなファイルパス(絶対パス)を生成して返す

Parameters
[in]directory: フォルダパス
[in]filePrefix: ファイル名の接頭辞 または NULL
[in]extName: ファイルの拡張子 (プレフィックス。.を含めること) または NULL

生成されるファイルパスは "<directory>/<filePrefix><ID><extName>" となります。 ID は時間情報をキーとして生成、
filePrefix、extName が NULL の場合は空文字扱いで結合されます。 例えば両方 NULL にすると、番号だけのファイル名になります。

◆ hasExtension()

bool ln::Path::hasExtension ( const StringRef ext = StringRef()) const

このパスが指定された拡張子を持っているかを確認します。 (ext の .

の有無は問わない)

◆ makeRelative()

Path ln::Path::makeRelative ( const Path target) const

このパスから指定したパスへの相対パスを取得します。

このパスと target はディレクトリの絶対パスである必要があります。

◆ replaceExtension()

Path ln::Path::replaceExtension ( const StringRef newExt) const

このパスの拡張子を変更した新しいパスを返します。

Parameters
[in]newExt: 新しい拡張子 (先頭の . は省略しても良い)
"file.txt" with "md" => "file.md"
"file" with "md" => "file.md"
"file.txt" with md" => "file"
"dir/file.txt" with "md" => "dir/file.md"

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