Conscience Core
Functions
conscience_utils::file_system Namespace Reference

Functions

fs::path resolvePathFromEnvironment (const char *envVar, const string &macro, std::optional< fs::path > defaultPath)
 
string readFileToString (const string &path)
 
bool canReadFile (const fs::path &filePath)
 
optional< unsigned > findLineInFile (const string &searchedString, const string &path, string *lineContent)
 
vector< unsigned char > * readFileToBytes (const string &path)
 
void writeStringToFile (const string &outPath, const string &content)
 
void writeBytesToFile (const string &outPath, const vector< unsigned char > &content)
 
void collectPathsRecursively (const fs::path &fromDirectory, vector< fs::path > &collectedPaths, const vector< string > &allowedExtensions)
 
bool isFileModifiedRecently (const fs::path &filePath, unsigned long long durationMillis)
 
bool isParentDirectory (const fs::path &filePath, const fs::path &directoryPath)
 
optional< bool > replaceLineInFile (const std::string &filePath, const std::string &searchedToken, const std::string &replacement)
 
fs::path resolvePathFromEnvironment (const char *envVar, const string &macro, optional< fs::path > defaultPath={})
 
bool hasExtension (const fs::path &filePath, const string &extension)
 
bool hasAnyExtension (const fs::path &filePath, const vector< string > &extensions)
 

Function Documentation

◆ canReadFile()

bool conscience_utils::file_system::canReadFile ( const fs::path &  filePath)

◆ collectPathsRecursively()

void conscience_utils::file_system::collectPathsRecursively ( const fs::path &  fromDirectory,
vector< fs::path > &  collectedPaths,
const vector< string > &  allowedExtensions = {} 
)
Parameters
collectedPathspaths will be collected recursively into this vector. It could be not empty
allowedExtensionsif empty, no filter will apply

◆ findLineInFile()

optional< unsigned > conscience_utils::file_system::findLineInFile ( const string &  searchedString,
const string &  path,
string *  lineContent = nullptr 
)

find first line number containing searchedString, or empty if not found

Parameters
lineContentif pointer is not null, found line text will be provided at this pointer (if line is not found, nothing is done)

◆ hasAnyExtension()

bool conscience_utils::file_system::hasAnyExtension ( const fs::path &  filePath,
const vector< string > &  extensions 
)
inline

◆ hasExtension()

bool conscience_utils::file_system::hasExtension ( const fs::path &  filePath,
const string &  extension 
)
inline
Parameters
extensioncan be prefixed with . or not, more efficient with dot

◆ isFileModifiedRecently()

bool conscience_utils::file_system::isFileModifiedRecently ( const fs::path &  filePath,
unsigned long long  durationMillis 
)

◆ isParentDirectory()

bool conscience_utils::file_system::isParentDirectory ( const fs::path &  filePath,
const fs::path &  directoryPath 
)

◆ readFileToBytes()

vector< unsigned char > * conscience_utils::file_system::readFileToBytes ( const string &  path)

◆ readFileToString()

string conscience_utils::file_system::readFileToString ( const string &  path)

reads UTF-8 file

◆ replaceLineInFile()

optional< bool > conscience_utils::file_system::replaceLineInFile ( const std::string &  filePath,
const std::string &  searchedToken,
const std::string &  replacement 
)

◆ resolvePathFromEnvironment() [1/2]

fs::path conscience_utils::file_system::resolvePathFromEnvironment ( const char *  envVar,
const string &  macro,
optional< fs::path >  defaultPath = {} 
)

◆ resolvePathFromEnvironment() [2/2]

fs::path conscience_utils::file_system::resolvePathFromEnvironment ( const char *  envVar,
const string &  macro,
std::optional< fs::path >  defaultPath 
)

◆ writeBytesToFile()

void conscience_utils::file_system::writeBytesToFile ( const string &  outPath,
const vector< unsigned char > &  content 
)

◆ writeStringToFile()

void conscience_utils::file_system::writeStringToFile ( const string &  outPath,
const string &  content 
)