LLVM 22.0.0git
llvm::sys::path Namespace Reference

Classes

class  const_iterator
 Path iterator. More...
class  reverse_iterator
 Reverse path iterator. More...

Enumerations

enum class  Style {
  native , posix , windows_slash , windows_backslash ,
  windows = windows_backslash
}

Functions

constexpr bool is_style_posix (Style S)
 Check if S uses POSIX path rules.
constexpr bool is_style_windows (Style S)
 Check if S uses Windows path rules.
reverse_iterator rbegin (StringRef Path, Style style)
reverse_iterator rend (StringRef Path)
static bool starts_with (StringRef Path, StringRef Prefix, Style style=Style::native)
StringRef remove_leading_dotslash (StringRef Path, Style style)
Lexical Component Iterator
LLVM_ABI const_iterator begin (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get begin iterator over path.
LLVM_ABI const_iterator end (StringRef path LLVM_LIFETIME_BOUND)
 Get end iterator over path.
LLVM_ABI reverse_iterator rbegin (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get reverse begin iterator over path.
LLVM_ABI reverse_iterator rend (StringRef path LLVM_LIFETIME_BOUND)
 Get reverse end iterator over path.
Lexical Modifiers
LLVM_ABI void remove_filename (SmallVectorImpl< char > &path, Style style=Style::native)
 Remove the last component from path unless it is the root dir.
LLVM_ABI void replace_extension (SmallVectorImpl< char > &path, const Twine &extension, Style style=Style::native)
 Replace the file extension of path with extension.
LLVM_ABI bool replace_path_prefix (SmallVectorImpl< char > &Path, StringRef OldPrefix, StringRef NewPrefix, Style style=Style::native)
 Replace matching path prefix with another path.
LLVM_ABI StringRef remove_leading_dotslash (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Remove redundant leading "./" pieces and consecutive separators.
LLVM_ABI bool remove_dots (SmallVectorImpl< char > &path, bool remove_dot_dot=false, Style style=Style::native)
 In-place remove any '.
LLVM_ABI void append (SmallVectorImpl< char > &path, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
 Append to path.
LLVM_ABI void append (SmallVectorImpl< char > &path, Style style, const Twine &a, const Twine &b="", const Twine &c="", const Twine &d="")
LLVM_ABI void append (SmallVectorImpl< char > &path, const_iterator begin, const_iterator end, Style style=Style::native)
 Append to path.
Transforms (or some other better name)
LLVM_ABI void native (const Twine &path, SmallVectorImpl< char > &result, Style style=Style::native)
 Convert path to the native form.
LLVM_ABI void native (SmallVectorImpl< char > &path, Style style=Style::native)
 Convert path to the native form in place.
void make_preferred (SmallVectorImpl< char > &path, Style style=Style::native)
 For Windows path styles, convert path to use the preferred path separators.
LLVM_ABI std::string convert_to_slash (StringRef path, Style style=Style::native)
 Replaces backslashes with slashes if Windows.
Lexical Observers
LLVM_ABI StringRef root_name (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get root name.
LLVM_ABI StringRef root_directory (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get root directory.
LLVM_ABI StringRef root_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get root path.
LLVM_ABI StringRef relative_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get relative path.
LLVM_ABI StringRef parent_path (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get parent path.
LLVM_ABI StringRef filename (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get filename.
LLVM_ABI StringRef stem (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get stem.
LLVM_ABI StringRef extension (StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
 Get extension.
LLVM_ABI bool is_separator (char value, Style style=Style::native)
 Check whether the given char is a path separator on the host OS.
LLVM_ABI StringRef get_separator (Style style=Style::native)
 Return the preferred separator for this platform.
LLVM_ABI void system_temp_directory (bool erasedOnReboot, SmallVectorImpl< char > &result)
 Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".
LLVM_ABI bool home_directory (SmallVectorImpl< char > &result)
 Get the user's home directory.
LLVM_ABI bool user_config_directory (SmallVectorImpl< char > &result)
 Get the directory where packages should read user-specific configurations.
LLVM_ABI bool cache_directory (SmallVectorImpl< char > &result)
 Get the directory where installed packages should put their machine-local cache, e.g.
LLVM_ABI bool has_root_name (const Twine &path, Style style=Style::native)
 Has root name?
LLVM_ABI bool has_root_directory (const Twine &path, Style style=Style::native)
 Has root directory?
LLVM_ABI bool has_root_path (const Twine &path, Style style=Style::native)
 Has root path?
LLVM_ABI bool has_relative_path (const Twine &path, Style style=Style::native)
 Has relative path?
LLVM_ABI bool has_parent_path (const Twine &path, Style style=Style::native)
 Has parent path?
LLVM_ABI bool has_filename (const Twine &path, Style style=Style::native)
 Has filename?
LLVM_ABI bool has_stem (const Twine &path, Style style=Style::native)
 Has stem?
LLVM_ABI bool has_extension (const Twine &path, Style style=Style::native)
 Has extension?
LLVM_ABI bool is_absolute (const Twine &path, Style style=Style::native)
 Is path absolute?
LLVM_ABI bool is_absolute_gnu (const Twine &path, Style style=Style::native)
 Is path absolute using GNU rules?
LLVM_ABI bool is_relative (const Twine &path, Style style=Style::native)
 Is path relative?

Enumeration Type Documentation

◆ Style

enum class llvm::sys::path::Style
strong
Enumerator
native 
posix 
windows_slash 
windows_backslash 
windows 

Definition at line 28 of file Path.h.

Function Documentation

◆ append() [1/3]

void llvm::sys::path::append ( SmallVectorImpl< char > & path,
const Twine & a,
const Twine & b = "",
const Twine & c = "",
const Twine & d = "" )

Append to path.

/foo + bar/f => /foo/bar/f
/foo/ + bar/f => /foo/bar/f
foo + bar/f => foo/bar/f
foo + /bar/f => foo/bar/f (FIXME: will be changed to /bar/f to align
with C++17 std::filesystem::path::append)
@ C
The default llvm calling convention, compatible with C.
Definition CallingConv.h:34
Parameters
pathSet to path + component.
aThe component to be appended to path.

Definition at line 456 of file Path.cpp.

References append(), and native.

Referenced by llvm::FileCollector::addFileImpl(), llvm::analyzeImportedModule(), llvm::dwarf_linker::parallel::CompileUnit::analyzeImportedModule(), append(), append(), llvm::appendArchToWindowsSDKLibPath(), codegen(), llvm::computeArchiveRelativePath(), llvm::logicalview::LVReader::createAlternativePath(), llvm::sys::fs::createUniquePath(), llvm::remarks::createYAMLParserFromMeta(), ExpandBasePaths(), llvm::cl::ExpansionContext::expandResponseFiles(), llvm::object::BuildIDFetcher::fetch(), fillLineInfoFromLocation(), llvm::cl::ExpansionContext::findConfigFile(), llvm::object::MachOObjectFile::findDsymObjectMembers(), llvm::sys::Process::FindInEnvPath(), findInputFile(), findSrcDirMap(), llvm::findVCToolChainViaCommandLine(), llvm::findVCToolChainViaEnvironment(), llvm::findVCToolChainViaRegistry(), llvm::findVCToolChainViaSetupConfig(), llvm::DiagnosticLocation::getAbsolutePath(), llvm::getCachedOrDownloadArtifact(), llvm::getDebuginfodDebuginfoUrlPath(), llvm::getDebuginfodExecutableUrlPath(), llvm::getDebuginfodSourceUrlPath(), llvm::getDefaultDebuginfodCacheDirectory(), llvm::LineEditor::getDefaultHistoryPath(), llvm::dwarf_linker::parallel::CompileUnit::getDirAndFilenameFromLineTable(), llvm::dwarf_linker::parallel::CompileUnit::getFileName(), getFilename(), llvm::DWARFDebugLine::Prologue::getFileNameByIndex(), llvm::object::Archive::Child::getFullName(), llvm::unittest::getInputFileDirectory(), llvm::vfs::RedirectingFileSystem::LookupResult::getPath(), llvm::gsym::LookupResult::getSourceFile(), llvm::getSubDirectoryPath(), getVFSEntries(), getWindows10SDKVersionFromPath(), llvm::getWindowsSDKDir(), getWindowsSDKDirViaCommandLine(), llvm::dwarf_linker::parallel::DWARFLinkerImpl::LinkContext::loadClangModule(), llvm::localCache(), llvm::vfs::RedirectingFileSystem::LookupResult::LookupResult(), llvm::sys::fs::make_absolute(), llvm::MachO::make_relative(), llvm::SourceMgr::OpenIncludeFile(), llvm::unittest::TempDir::path(), llvm::pruneCache(), llvm::sys::fs::directory_entry::replace_filename(), llvm::dwarf_linker::classic::CachedPathResolver::resolve(), llvm::resolveRelativeObjectPath(), resolveRelativeObjectPath(), llvm::AMDGPUSplitModulePass::run(), llvm::pdb::NativeSession::searchForPdb(), llvm::MCContext::setGenDwarfRootFile(), llvm::useUniversalCRT(), and llvm::ThinLTOCodeGenerator::writeGeneratedObject().

◆ append() [2/3]

void llvm::sys::path::append ( SmallVectorImpl< char > & path,
const_iterator begin,
const_iterator end,
Style style = Style::native )

Append to path.

/foo + [bar,f] => /foo/bar/f
/foo/ + [bar,f] => /foo/bar/f
foo + [bar,f] => foo/bar/f
Parameters
pathSet to path + [begin, end).
beginStart of components to append.
endOne past the end of components to append.

Definition at line 461 of file Path.cpp.

References append(), begin(), and end().

◆ append() [3/3]

◆ begin()

const_iterator llvm::sys::path::begin ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get begin iterator over path.

Parameters
pathInput path.
Returns
Iterator initialized with the first component of path.

Definition at line 226 of file Path.cpp.

Referenced by append(), llvm::computeArchiveRelativePath(), llvm::vfs::RedirectingFileSystem::create(), llvm::vfs::RedirectingFileSystem::lookupPath(), llvm::MachO::make_relative(), pathHasTraversal(), remove_leading_dotslash(), root_directory(), root_name(), and root_path().

◆ cache_directory()

LLVM_ABI bool llvm::sys::path::cache_directory ( SmallVectorImpl< char > & result)

Get the directory where installed packages should put their machine-local cache, e.g.

$XDG_CACHE_HOME.

Parameters
resultHolds the resulting path name.
Returns
True if the appropriate path was determined, it need not exist.

References LLVM_ABI, and native.

Referenced by llvm::getDefaultDebuginfodCacheDirectory().

◆ convert_to_slash()

std::string llvm::sys::path::convert_to_slash ( StringRef path,
Style style = Style::native )

Replaces backslashes with slashes if Windows.

Parameters
pathprocessed path
Returns
The result of replacing backslashes with forward slashes if Windows. On Unix, this function is a no-op because backslashes are valid path chracters.

Definition at line 568 of file Path.cpp.

References is_style_posix(), and llvm::replace().

Referenced by llvm::TarWriter::append(), llvm::computeArchiveRelativePath(), llvm::logicalview::LVReader::createAlternativePath(), llvm::getDebuginfodSourceUrlPath(), and searchForExe().

◆ end()

const_iterator llvm::sys::path::end ( StringRef path LLVM_LIFETIME_BOUND)

◆ extension()

StringRef llvm::sys::path::extension ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get extension.

If filename contains a dot but not solely one or two dots, result is the substring of filename starting at (and including) the last dot, and ending at the end of path. Otherwise "".

/foo/bar.txt => .txt
/foo/bar => <empty>
/foo/.txt => .txt
Parameters
pathInput path.
Returns
The extension of path.

Definition at line 590 of file Path.cpp.

References filename(), llvm::StringRef::find_last_of(), llvm::StringRef::npos, llvm::StringRef::size(), and llvm::StringRef::substr().

Referenced by llvm::DWARFContext::dump(), llvm::object::MachOObjectFile::findDsymObjectMembers(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), has_extension(), rend(), and replace_extension().

◆ filename()

◆ get_separator()

StringRef llvm::sys::path::get_separator ( Style style = Style::native)

Return the preferred separator for this platform.

Returns
StringRef of the preferred separator, null-terminated.

Definition at line 609 of file Path.cpp.

References windows.

Referenced by EmitGenDwarfInfo().

◆ has_extension()

bool llvm::sys::path::has_extension ( const Twine & path,
Style style = Style::native )

Has extension?

extension != ""

Parameters
pathInput path.
Returns
True if the path has a extension, false otherwise.

Definition at line 664 of file Path.cpp.

References llvm::StringRef::empty(), and extension().

◆ has_filename()

bool llvm::sys::path::has_filename ( const Twine & path,
Style style = Style::native )

Has filename?

filename != ""

Parameters
pathInput path.
Returns
True if the path has a filename, false otherwise.

Definition at line 643 of file Path.cpp.

References llvm::StringRef::empty(), and filename().

◆ has_parent_path()

bool llvm::sys::path::has_parent_path ( const Twine & path,
Style style = Style::native )

Has parent path?

parent_path != ""

Parameters
pathInput path.
Returns
True if the path has a parent path, false otherwise.

Definition at line 650 of file Path.cpp.

References llvm::StringRef::empty(), and parent_path().

Referenced by llvm::cl::ExpansionContext::findConfigFile().

◆ has_relative_path()

bool llvm::sys::path::has_relative_path ( const Twine & path,
Style style = Style::native )

Has relative path?

relative_path != ""

Parameters
pathInput path.
Returns
True if the path has a relative path, false otherwise.

Definition at line 636 of file Path.cpp.

References llvm::StringRef::empty(), and relative_path().

◆ has_root_directory()

bool llvm::sys::path::has_root_directory ( const Twine & path,
Style style = Style::native )

Has root directory?

root_directory != ""

Parameters
pathInput path.
Returns
True if the path has a root directory, false otherwise.

Definition at line 622 of file Path.cpp.

References llvm::StringRef::empty(), and root_directory().

Referenced by is_absolute(), and llvm::sys::fs::make_absolute().

◆ has_root_name()

bool llvm::sys::path::has_root_name ( const Twine & path,
Style style = Style::native )

Has root name?

root_name != ""

Parameters
pathInput path.
Returns
True if the path has a root name, false otherwise.

Definition at line 615 of file Path.cpp.

References llvm::StringRef::empty(), and root_name().

Referenced by append(), is_absolute(), and llvm::sys::fs::make_absolute().

◆ has_root_path()

bool llvm::sys::path::has_root_path ( const Twine & path,
Style style = Style::native )

Has root path?

root_path != ""

Parameters
pathInput path.
Returns
True if the path has a root path, false otherwise.

Definition at line 629 of file Path.cpp.

References llvm::StringRef::empty(), and root_path().

◆ has_stem()

bool llvm::sys::path::has_stem ( const Twine & path,
Style style = Style::native )

Has stem?

stem != ""

Parameters
pathInput path.
Returns
True if the path has a stem, false otherwise.

Definition at line 657 of file Path.cpp.

References llvm::StringRef::empty(), and stem().

◆ home_directory()

LLVM_ABI bool llvm::sys::path::home_directory ( SmallVectorImpl< char > & result)

Get the user's home directory.

Parameters
resultHolds the resulting path name.
Returns
True if a home directory is set, false otherwise.

References LLVM_ABI.

Referenced by llvm::LineEditor::getDefaultHistoryPath(), and native().

◆ is_absolute()

bool llvm::sys::path::is_absolute ( const Twine & path,
Style style = Style::native )

Is path absolute?

According to cppreference.com, C++17 states: "An absolute path is a path that unambiguously identifies the location of a file without reference to an additional starting location."

In other words, the rules are: 1) POSIX style paths with nonempty root directory are absolute. 2) Windows style paths with nonempty root name and root directory are absolute. 3) No other paths are absolute.

See also
has_root_name
has_root_directory
Parameters
pathInput path.
Returns
True if the path is absolute, false if it is not.

Definition at line 671 of file Path.cpp.

References has_root_directory(), has_root_name(), and is_style_posix().

Referenced by llvm::sys::fs::createUniquePath(), ExpandBasePaths(), llvm::FileCollector::FileCollector(), llvm::sys::Process::FindInEnvPath(), llvm::DiagnosticLocation::getAbsolutePath(), llvm::object::Archive::Child::getFullName(), llvm::pdb::PDBSymbolCompiland::getSourceFileFullPath(), is_relative(), isPathAbsoluteOnWindowsOrPosix(), llvm::dwarf_linker::isPathAbsoluteOnWindowsOrPosix(), llvm::sys::fs::make_absolute(), llvm::vfs::FileSystem::makeAbsolute(), and llvm::vfs::RedirectingFileSystem::makeAbsolute().

◆ is_absolute_gnu()

bool llvm::sys::path::is_absolute_gnu ( const Twine & path,
Style style = Style::native )

Is path absolute using GNU rules?

GNU rules are: 1) Paths starting with a path separator are absolute. 2) Windows style paths are also absolute if they start with a character followed by ':'. 3) No other paths are absolute.

On Windows style the path "C:\Users\Default" has "C:" as root name and "\" as root directory. Hence "C:" on Windows is absolute under GNU rules and not absolute under C++17 because it has no root directory. Likewise "/" and "" on Windows are absolute under GNU and are not absolute under C++17 due to empty root name.

See also
has_root_name
has_root_directory
Parameters
pathInput path.
styleThe style of path (e.g. Windows or POSIX). "native" style means to derive the style from the host.
Returns
True if the path is absolute following GNU rules, false if it is not.

Definition at line 681 of file Path.cpp.

References is_separator(), and is_style_windows().

◆ is_relative()

◆ is_separator()

bool llvm::sys::path::is_separator ( char value,
Style style = Style::native )

Check whether the given char is a path separator on the host OS.

Parameters
valuea character
Returns
true if value is a path separator character on the host OS

Definition at line 601 of file Path.cpp.

References is_style_windows().

Referenced by append(), llvm::orc::DumpObjects::DumpObjects(), is_absolute_gnu(), native(), llvm::sys::path::const_iterator::operator++(), llvm::sys::path::reverse_iterator::operator++(), remove_leading_dotslash(), root_directory(), root_name(), root_path(), llvm::MCContext::setGenDwarfRootFile(), starts_with(), and llvm::stripDirPrefix().

◆ is_style_posix()

bool llvm::sys::path::is_style_posix ( Style S)
constexpr

Check if S uses POSIX path rules.

Definition at line 37 of file Path.h.

References native, and posix.

Referenced by convert_to_slash(), is_absolute(), and is_style_windows().

◆ is_style_windows()

bool llvm::sys::path::is_style_windows ( Style S)
constexpr

◆ make_preferred()

void llvm::sys::path::make_preferred ( SmallVectorImpl< char > & path,
Style style = Style::native )
inline

For Windows path styles, convert path to use the preferred path separators.

For other styles, do nothing.

Parameters
pathA path that is transformed to preferred format.

Definition at line 278 of file Path.h.

References is_style_windows(), and native.

Referenced by remove_dots().

◆ native() [1/2]

void llvm::sys::path::native ( const Twine & path,
SmallVectorImpl< char > & result,
Style style = Style::native )

Convert path to the native form.

This is used to give paths to users and operating system calls in the platform's normal way. For example, on Windows all '/' are converted to '\'. On Unix, it converts all '\' to '/'.

Parameters
pathA path that is transformed to native format.
resultHolds the result of the transformation.

Definition at line 540 of file Path.cpp.

References assert(), llvm::SmallVectorImpl< T >::clear(), llvm::SmallVectorTemplateCommon< T, typename >::data(), and native.

◆ native() [2/2]

void llvm::sys::path::native ( SmallVectorImpl< char > & path,
Style style = Style::native )

Convert path to the native form in place.

This is used to give paths to users and operating system calls in the platform's normal way. For example, on Windows all '/' are converted to '\'.

Parameters
pathA path that is transformed to native format.

Definition at line 550 of file Path.cpp.

References llvm::SmallString< InternalLen >::append(), home_directory(), is_separator(), is_style_windows(), and llvm::replace().

◆ parent_path()

◆ rbegin() [1/2]

LLVM_ABI reverse_iterator llvm::sys::path::rbegin ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get reverse begin iterator over path.

Parameters
pathInput path.
Returns
Iterator initialized with the first reverse component of path.

References LLVM_ABI, LLVM_LIFETIME_BOUND, and native.

Referenced by filename(), llvm::findVCToolChainViaEnvironment(), llvm::dwarf_linker::guessDeveloperDir(), and llvm::dwarf_linker::isInToolchainDir().

◆ rbegin() [2/2]

reverse_iterator llvm::sys::path::rbegin ( StringRef Path,
Style style )

Definition at line 297 of file Path.cpp.

References I.

◆ relative_path()

StringRef llvm::sys::path::relative_path ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get relative path.

C:\hello\world => hello\world
foo/bar => foo/bar
/foo/bar => foo/bar
Parameters
pathInput path.
Returns
The path starting after root_path if one exists, otherwise "".

Definition at line 413 of file Path.cpp.

References root_path(), and llvm::StringRef::size().

Referenced by llvm::FileCollector::addFileImpl(), has_relative_path(), and llvm::sys::fs::make_absolute().

◆ remove_dots()

◆ remove_filename()

void llvm::sys::path::remove_filename ( SmallVectorImpl< char > & path,
Style style = Style::native )

Remove the last component from path unless it is the root dir.

Similar to the POSIX "dirname" utility.

directory/filename.cpp => directory/
directory/ => directory
filename.cpp => <empty>
/ => /
LLVM_ABI StringRef filename(StringRef path LLVM_LIFETIME_BOUND, Style style=Style::native)
Get filename.
Definition Path.cpp:577
Parameters
pathA path that is modified to not have a file component.

Definition at line 474 of file Path.cpp.

References llvm::StringRef::npos.

Referenced by llvm::pdb::NativeSession::searchForPdb(), and llvm::MCContext::setGenDwarfRootFile().

◆ remove_leading_dotslash() [1/2]

LLVM_ABI StringRef llvm::sys::path::remove_leading_dotslash ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Remove redundant leading "./" pieces and consecutive separators.

Parameters
pathInput path.
Returns
The cleaned-up path.

References begin(), end(), LLVM_ABI, LLVM_LIFETIME_BOUND, and native.

Referenced by llvm::BasicBlockSectionsProfileReaderWrapperPass::doInitialization(), llvm::DiagnosticLocation::getAbsolutePath(), and makeAbsolute().

◆ remove_leading_dotslash() [2/2]

StringRef llvm::sys::path::remove_leading_dotslash ( StringRef Path,
Style style )

Definition at line 703 of file Path.cpp.

References is_separator().

◆ rend() [1/2]

LLVM_ABI reverse_iterator llvm::sys::path::rend ( StringRef path LLVM_LIFETIME_BOUND)

Get reverse end iterator over path.

Parameters
pathInput path.
Returns
Iterator initialized to the reverse end of path.

References extension(), LLVM_ABI, LLVM_LIFETIME_BOUND, and native.

Referenced by llvm::findVCToolChainViaEnvironment(), llvm::dwarf_linker::guessDeveloperDir(), and llvm::dwarf_linker::isInToolchainDir().

◆ rend() [2/2]

reverse_iterator llvm::sys::path::rend ( StringRef Path)

Definition at line 306 of file Path.cpp.

References I.

◆ replace_extension()

void llvm::sys::path::replace_extension ( SmallVectorImpl< char > & path,
const Twine & extension,
Style style = Style::native )

Replace the file extension of path with extension.

./filename.cpp => ./filename.extension
./filename => ./filename.extension
./ => ./.extension
Parameters
pathA path that has its extension replaced with extension.
extensionThe extension to be added. It may be empty. It may also optionally start with a '.', if it does not, one will be prepended.

Definition at line 480 of file Path.cpp.

References llvm::StringRef::begin(), llvm::StringRef::end(), extension(), llvm::StringRef::npos, and llvm::StringRef::size().

Referenced by getDefaultOutputPath(), llvm::MachO::replace_extension(), searchForExe(), and searchForObj().

◆ replace_path_prefix()

bool llvm::sys::path::replace_path_prefix ( SmallVectorImpl< char > & Path,
StringRef OldPrefix,
StringRef NewPrefix,
Style style = Style::native )

Replace matching path prefix with another path.

/foo, /old, /new => /foo
/old, /old, /new => /new
/old, /old/, /new => /old
/old/foo, /old, /new => /new/foo
/old/foo, /old/, /new => /new/foo
/old/foo, /old/, /new/ => /new/foo
/oldfoo, /old, /new => /oldfoo
/foo, <empty>, /new => /new/foo
/foo, <empty>, new => new/foo
/old/foo, /old, <empty> => /foo
Parameters
PathIf Path starts with OldPrefix modify to instead start with NewPrefix.
OldPrefixThe path prefix to strip from Path.
NewPrefixThe path prefix to replace NewPrefix with.
styleThe style used to match the prefix. Exact match using Posix style, case/separator insensitive match for Windows style.
Returns
true if Path begins with OldPrefix

Definition at line 518 of file Path.cpp.

References llvm::copy(), llvm::StringRef::empty(), llvm::StringRef::size(), starts_with(), and llvm::StringRef::substr().

Referenced by llvm::lto::getThinLTOOutputFile(), llvm::MCContext::remapDebugPath(), llvm::remapPath(), and remapPath().

◆ root_directory()

StringRef llvm::sys::path::root_directory ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get root directory.

/goo/hello => /
c:/hello => /
d/file.txt => <empty>
dot regions Print regions of function to dot file(with no function bodies)"
Parameters
pathInput path.
Returns
The root directory of path if it has one, otherwise "".

Definition at line 390 of file Path.cpp.

References begin(), end(), is_separator(), and is_style_windows().

Referenced by has_root_directory(), and llvm::sys::fs::make_absolute().

◆ root_name()

StringRef llvm::sys::path::root_name ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get root name.

//net/hello => //net
c:/hello => c: (on Windows, on other platforms nothing)
/hello => <empty>
Parameters
pathInput path.
Returns
The root name of path if it has one, otherwise "".

Definition at line 373 of file Path.cpp.

References begin(), end(), is_separator(), and is_style_windows().

Referenced by llvm::computeArchiveRelativePath(), has_root_name(), and llvm::sys::fs::make_absolute().

◆ root_path()

StringRef llvm::sys::path::root_path ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get root path.

Equivalent to root_name + root_directory.

Parameters
pathInput path.
Returns
The root path of path if it has one, otherwise "".

Definition at line 348 of file Path.cpp.

References begin(), end(), is_separator(), and is_style_windows().

Referenced by has_root_path(), relative_path(), and remove_dots().

◆ starts_with()

bool llvm::sys::path::starts_with ( StringRef Path,
StringRef Prefix,
Style style = Style::native )
static

Definition at line 499 of file Path.cpp.

References I, is_separator(), is_style_windows(), native, and llvm::toLower().

Referenced by replace_path_prefix().

◆ stem()

StringRef llvm::sys::path::stem ( StringRef path LLVM_LIFETIME_BOUND,
Style style = Style::native )

Get stem.

If filename contains a dot but not solely one or two dots, result is the substring of filename ending at (but not including) the last dot. Otherwise it is filename.

/foo/bar.txt => bar
/foo/bar => bar
/foo/.txt => <empty>
/foo/. => .
/foo/.. => ..
Parameters
pathInput path.
Returns
The stem of path.

Definition at line 579 of file Path.cpp.

References filename(), llvm::StringRef::find_last_of(), llvm::StringRef::npos, llvm::StringRef::size(), and llvm::StringRef::substr().

Referenced by llvm::TargetLoweringObjectFileGOFF::getModuleMetadata(), and has_stem().

◆ system_temp_directory()

LLVM_ABI void llvm::sys::path::system_temp_directory ( bool erasedOnReboot,
SmallVectorImpl< char > & result )

Get the typical temporary directory for the system, e.g., "/var/tmp" or "C:/TEMP".

Parameters
erasedOnRebootWhether to favor a path that is erased on reboot rather than one that potentially persists longer. This parameter will be ignored if the user or system has set the typical environment variable (e.g., TEMP on Windows, TMPDIR on *nix) to specify a temporary directory.
resultHolds the resulting path name.

References LLVM_ABI.

Referenced by llvm::sys::fs::createUniquePath(), and llvm::AMDGPUSplitModulePass::run().

◆ user_config_directory()

LLVM_ABI bool llvm::sys::path::user_config_directory ( SmallVectorImpl< char > & result)

Get the directory where packages should read user-specific configurations.

e.g. $XDG_CONFIG_HOME.

Parameters
resultHolds the resulting path name.
Returns
True if the appropriate path was determined, it need not exist.

References LLVM_ABI.