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

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

◆ begin()

const_iterator llvm::sys::path::begin ( StringRef  path,
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(), root_directory(), root_name(), and root_path().

◆ cache_directory()

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.

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::StringRef::str().

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

◆ end()

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

Get end iterator over path.

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

Definition at line 235 of file Path.cpp.

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

◆ extension()

StringRef llvm::sys::path::extension ( StringRef  path,
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(), and replace_extension().

◆ filename()

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

◆ 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(), extension(), and llvm::Twine::toStringRef().

◆ 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(), filename(), and llvm::Twine::toStringRef().

◆ 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(), parent_path(), and llvm::Twine::toStringRef().

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(), relative_path(), and llvm::Twine::toStringRef().

◆ 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(), root_directory(), and llvm::Twine::toStringRef().

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(), root_name(), and llvm::Twine::toStringRef().

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(), root_path(), and llvm::Twine::toStringRef().

◆ 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(), stem(), and llvm::Twine::toStringRef().

◆ home_directory()

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.

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(), is_style_posix(), and llvm::Twine::toStringRef().

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(), llvm::dwarf_linker::isPathAbsoluteOnWindowsOrPosix(), 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(), is_style_windows(), and llvm::Twine::toStringRef().

◆ is_relative()

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

◆ 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_separator(), is_style_windows(), and value.

Referenced by append(), llvm::orc::DumpObjects::DumpObjects(), is_absolute_gnu(), is_separator(), 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()

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

Check if S uses POSIX path rules.

Definition at line 36 of file Path.h.

References native, and posix.

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

◆ is_style_windows()

constexpr 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 269 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(), llvm::StringRef::data(), llvm::Twine::getSingleStringRef(), llvm::Twine::isSingleStringRef(), native, and llvm::Twine::toVector().

◆ 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(), and is_style_windows().

◆ parent_path()

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

◆ rbegin()

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

Get reverse begin iterator over path.

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

Definition at line 297 of file Path.cpp.

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

◆ relative_path()

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

Get relative path.

C:\hello\world => hello\world
foo/bar => foo/bar
/foo/bar => foo/bar
@ C
The default llvm calling convention, compatible with C.
Definition: CallingConv.h:34
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(), llvm::StringRef::size(), and llvm::StringRef::substr().

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

◆ remove_dots()

bool llvm::sys::path::remove_dots ( SmallVectorImpl< char > &  path,
bool  remove_dot_dot = false,
Style  style = Style::native 
)

◆ 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>
/ => /
StringRef filename(StringRef path, 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::SmallVectorTemplateCommon< T, typename >::begin(), llvm::StringRef::npos, llvm::SmallVectorBase< Size_T >::size(), and llvm::SmallVectorImpl< T >::truncate().

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

◆ remove_leading_dotslash()

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

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

Parameters
pathInput path.
Returns
The cleaned-up path.

Definition at line 703 of file Path.cpp.

References is_separator().

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

◆ rend()

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

Get reverse end iterator over path.

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

Definition at line 306 of file Path.cpp.

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

◆ 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::SmallVectorImpl< T >::append(), llvm::SmallVectorTemplateCommon< T, typename >::begin(), llvm::StringRef::begin(), llvm::StringRef::end(), extension(), llvm::StringRef::npos, llvm::SmallVectorTemplateBase< T, bool >::push_back(), llvm::SmallVectorBase< Size_T >::size(), llvm::StringRef::size(), and llvm::SmallVectorImpl< T >::truncate().

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(), remapPath(), and llvm::remapPath().

◆ root_directory()

StringRef llvm::sys::path::root_directory ( StringRef  path,
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,
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,
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(), is_style_windows(), and llvm::StringRef::substr().

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

◆ starts_with()

static 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(), and starts_with().

◆ stem()

StringRef llvm::sys::path::stem ( StringRef  path,
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 has_stem().

◆ system_temp_directory()

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.

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

◆ user_config_directory()

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.