cpplocate  1.0.0.a8d87a94e3ab
C++ Locator Library
Functions
cpplocate::utils Namespace Reference

Functions

CPPLOCATE_API void replace (std::string &str, const std::string &original, const std::string &substitute)
 
CPPLOCATE_API void trim (std::string &str)
 
CPPLOCATE_API std::string trimPath (const std::string &str)
 
CPPLOCATE_API std::string trimPath (std::string &&str)
 
CPPLOCATE_API std::string unifiedPath (const std::string &path)
 
CPPLOCATE_API std::string unifiedPath (std::string &&path)
 
CPPLOCATE_API std::string getDirectoryPath (const std::string &fullpath)
 
CPPLOCATE_API size_t posAfterString (const std::string &str, const std::string &substr)
 
CPPLOCATE_API std::string getSystemBasePath (const std::string &path)
 
CPPLOCATE_API void split (const std::string &str, char delim, std::vector< std::string > &values)
 
CPPLOCATE_API std::string join (const std::vector< std::string > &values, const std::string &delim)
 
CPPLOCATE_API void getPaths (const std::string &str, std::vector< std::string > &values)
 
CPPLOCATE_API std::string getEnv (const std::string &name)
 
CPPLOCATE_API bool fileExists (const std::string &path)
 
CPPLOCATE_API bool loadModule (const std::string &directory, const std::string &name, ModuleInfo &info)
 

Function Documentation

CPPLOCATE_API void cpplocate::utils::replace ( std::string &  str,
const std::string &  original,
const std::string &  substitute 
)

Replace all occurences of a substring in string.

Parameters
[in,out]strString
[in]originalOriginal string
[in]substituteSubstitute string
CPPLOCATE_API void cpplocate::utils::trim ( std::string &  str)

Remove spaces at the beginning and the end of a string.

Parameters
[in,out]strString
CPPLOCATE_API std::string cpplocate::utils::trimPath ( const std::string &  str)

Remove spaces and trailing slash/backslash from path.

Parameters
[in]pathPath
Returns
Trimmed path
CPPLOCATE_API std::string cpplocate::utils::trimPath ( std::string &&  str)

Remove spaces and trailing slash/backslash from path.

Parameters
[in]pathPath
Returns
Trimmed path
CPPLOCATE_API std::string cpplocate::utils::unifiedPath ( const std::string &  path)

Convert path into unified form (replace '\' with '/')

Parameters
[in]pathPath
Returns
Path with forward slashes
CPPLOCATE_API std::string cpplocate::utils::unifiedPath ( std::string &&  path)

Convert path into unified form (replace '\' with '/')

Parameters
[in]pathPath
Returns
Path with forward slashes
CPPLOCATE_API std::string cpplocate::utils::getDirectoryPath ( const std::string &  fullpath)

Cut away filename portion of a path, get path to directory.

Parameters
[in]fullpathPath (e.g., '/path/to/file.txt')
Returns
Directory path (e.g., '/path/to')
CPPLOCATE_API size_t cpplocate::utils::posAfterString ( const std::string &  str,
const std::string &  substr 
)

Get position right after given substring (searched from right to left)

Parameters
[in]strFull string
[in]substrSubstring to search for
Returns
Position after substring if substring was found, else string::npos
CPPLOCATE_API std::string cpplocate::utils::getSystemBasePath ( const std::string &  path)

Get system base path for path to library or executable.

Parameters
[in]pathPath to library or executable (e.g., '/usr/bin/myapp')
Returns
System path path (e.g., '/usr')
Remarks
This function returns the base path if the given file is a system path. Otherwise, it returns an empty string.

Examples: '/usr/bin/myapp' -> '/usr' '/usr/local/bin/myapp' -> '/usr/local' '/usr/lib/mylib.so' -> '/usr' '/usr/lib64/mylib.so' -> '/usr' '/usr/local/lib64/mylib.so' -> '/usr/local' '/crosscompile/armv4/usr/lib/mylib.so.2' -> '/crosscompile/armv4/usr'

CPPLOCATE_API void cpplocate::utils::split ( const std::string &  str,
char  delim,
std::vector< std::string > &  values 
)

Split string into array of strings.

Parameters
[in]strInput string
[in]delimDelimiter used to split the string
[out]valuesOutput vector
CPPLOCATE_API std::string cpplocate::utils::join ( const std::vector< std::string > &  values,
const std::string &  delim 
)

Join array of strings into a single string.

Parameters
[out]valuesInput vector
[in]delimDelimiter used to join the string
Returns
Joined string
CPPLOCATE_API void cpplocate::utils::getPaths ( const std::string &  str,
std::vector< std::string > &  values 
)

Split list of paths separated by : or ; into list of paths.

Parameters
[in]pathsInput string
[out]valuesOutput vector
Remarks
On windows, the separator ';' is used, ':' on all other systems
CPPLOCATE_API std::string cpplocate::utils::getEnv ( const std::string &  name)

Get value of environment variable.

Parameters
[in]nameName of environment variable
Returns
Value of the environment variable
CPPLOCATE_API bool cpplocate::utils::fileExists ( const std::string &  path)

Check if file or directory exists.

Parameters
[in]pathPath to file or directory
Returns
'true' if it exists, else 'false'
CPPLOCATE_API bool cpplocate::utils::loadModule ( const std::string &  directory,
const std::string &  name,
ModuleInfo info 
)

Load module information file.

Parameters
[in]directoryPath to directory
[in]nameModule name
[out]infoModule information
Returns
'true' if module could be loaded successfully, else 'false'
Remarks
The filename is constructed as <directory>/<name>.modinfo