www.mooseframework.org
Namespaces | Functions
MooseUtils.C File Reference

Go to the source code of this file.

Namespaces

 MooseUtils
 

Functions

std::filesystem::path MooseUtils::pathjoin (const std::filesystem::path &p)
 
std::string MooseUtils::runTestsExecutable ()
 Returns the location of either a local repo run_tests script - or an installed test executor script if run_tests isn't found. More...
 
std::string MooseUtils::findTestRoot ()
 Searches in the current working directory and then recursively up in each parent directory looking for a "testroot" file. More...
 
bool MooseUtils::parsesToReal (const std::string &input)
 Check if the input string can be parsed into a Real. More...
 
std::string MooseUtils::installedInputsDir (const std::string &app_name, const std::string &dir_name, const std::string &extra_error_msg="")
 Returns the directory of any installed inputs or the empty string if none are found. More...
 
std::string MooseUtils::docsDir (const std::string &app_name)
 Returns the directory of any installed docs/site. More...
 
std::string MooseUtils::replaceAll (std::string str, const std::string &from, const std::string &to)
 Replaces all occurences of from in str with to and returns the result. More...
 
std::string MooseUtils::convertLatestCheckpoint (std::string orig)
 Replaces "LATEST" placeholders with the latest checkpoint file name. More...
 
int MooseUtils::levenshteinDist (const std::string &s1, const std::string &s2)
 Computes and returns the Levenshtein distance between strings s1 and s2. More...
 
void MooseUtils::escape (std::string &str)
 This function will escape all of the standard C++ escape characters so that they can be printed. More...
 
std::string MooseUtils::trim (const std::string &str, const std::string &white_space=" \\\)
 Standard scripting language trim function. More...
 
bool MooseUtils::pathContains (const std::string &expression, const std::string &string_to_find, const std::string &delims="/")
 This function tokenizes a path and checks to see if it contains the string to look for. More...
 
bool MooseUtils::pathExists (const std::string &path)
 
bool MooseUtils::pathIsDirectory (const std::string &path)
 
bool MooseUtils::checkFileReadable (const std::string &filename, bool check_line_endings=false, bool throw_on_unreadable=true, bool check_for_git_lfs_pointer=true)
 Checks to see if a file is readable (exists and permissions) More...
 
bool MooseUtils::checkForGitLFSPointer (std::ifstream &file)
 Check if the file is a Git-LFS pointer. More...
 
bool MooseUtils::checkFileWriteable (const std::string &filename, bool throw_on_unwritable=true)
 Check if the file is writable (path exists and permissions) More...
 
void MooseUtils::parallelBarrierNotify (const Parallel::Communicator &comm, bool messaging)
 
void MooseUtils::serialBegin (const libMesh::Parallel::Communicator &comm, bool warn=true)
 This function marks the begin of a section of code that is executed in serial rank by rank. More...
 
void MooseUtils::serialEnd (const libMesh::Parallel::Communicator &comm, bool warn=true)
 Closes a section of code that is executed in serial rank by rank, and that was opened with a call to serialBegin. More...
 
bool MooseUtils::hasExtension (const std::string &filename, std::string ext, bool strip_exodus_ext=false)
 Function tests if the supplied filename as the desired extension. More...
 
std::string MooseUtils::stripExtension (const std::string &s)
 Removes any file extension from the given string s (i.e. More...
 
std::string MooseUtils::getCurrentWorkingDir ()
 Returns the current working directory as a string. More...
 
void MooseUtils::makedirs (const std::string &dir_name, bool throw_on_failure=false)
 Recursively make directories. More...
 
void MooseUtils::removedirs (const std::string &dir_name, bool throw_on_failure=false)
 Recursively remove directories from inner-most when the directories are empty. More...
 
std::string MooseUtils::camelCaseToUnderscore (const std::string &camel_case_name)
 Function for converting a camel case name to a name containing underscores. More...
 
std::string MooseUtils::underscoreToCamelCase (const std::string &underscore_name, bool leading_upper_case)
 Function for converting an underscore name to a camel case name. More...
 
std::string MooseUtils::shortName (const std::string &name)
 Function for stripping name after the file / in parser block. More...
 
std::string MooseUtils::baseName (const std::string &name)
 Function for string the information before the final / in a parser block. More...
 
std::string MooseUtils::hostname ()
 Get the hostname the current process is running on. More...
 
unsigned short MooseUtils::getTermWidth (bool use_environment)
 Returns the width of the terminal using sys/ioctl. More...
 
void MooseUtils::MaterialPropertyStorageDump (const HashMap< const libMesh::Elem *, HashMap< unsigned int, MaterialProperties >> &props)
 Function to dump the contents of MaterialPropertyStorage for debugging purposes. More...
 
std::string & MooseUtils::removeColor (std::string &msg)
 remove ANSI escape sequences for terminal color from msg More...
 
void MooseUtils::addLineBreaks (std::string &message, unsigned int line_width)
 
void MooseUtils::indentMessage (const std::string &prefix, std::string &message, const char *color=COLOR_CYAN, bool dont_indent_first_line=true, const std::string &post_prefix=": ")
 Indents the supplied message given the prefix and color. More...
 
std::list< std::string > MooseUtils::listDir (const std::string path, bool files_only=false)
 
std::list< std::string > MooseUtils::getFilesInDirs (const std::list< std::string > &directory_list, const bool files_only=true)
 Retrieves the names of all of the files contained within the list of directories passed into the routine. More...
 
std::string MooseUtils::getLatestCheckpointFilePrefix (const std::list< std::string > &checkpoint_files)
 Returns the most recent checkpoint prefix (the four numbers at the begining) If a suitable file isn't found the empty string is returned. More...
 
bool MooseUtils::wildCardMatch (std::string name, std::string search_string)
 
bool MooseUtils::globCompare (const std::string &candidate, const std::string &pattern, std::size_t c=0, std::size_t p=0)
 
template<typename T >
MooseUtils::convertStringToInt (const std::string &str, bool throw_on_failure)
 
template<>
short int MooseUtils::convert< short int > (const std::string &str, bool throw_on_failure)
 
template<>
unsigned short int MooseUtils::convert< unsigned short int > (const std::string &str, bool throw_on_failure)
 
template<>
int MooseUtils::convert< int > (const std::string &str, bool throw_on_failure)
 
template<>
unsigned int MooseUtils::convert< unsigned int > (const std::string &str, bool throw_on_failure)
 
template<>
long int MooseUtils::convert< long int > (const std::string &str, bool throw_on_failure)
 
template<>
unsigned long int MooseUtils::convert< unsigned long int > (const std::string &str, bool throw_on_failure)
 
template<>
long long int MooseUtils::convert< long long int > (const std::string &str, bool throw_on_failure)
 
template<>
unsigned long long int MooseUtils::convert< unsigned long long int > (const std::string &str, bool throw_on_failure)
 
std::string MooseUtils::toUpper (const std::string &name)
 Convert supplied string to upper case. More...
 
std::string MooseUtils::toLower (const std::string &name)
 Convert supplied string to lower case. More...
 
ExecFlagEnum MooseUtils::getDefaultExecFlagEnum ()
 Return the default ExecFlagEnum for MOOSE. More...
 
int MooseUtils::stringToInteger (const std::string &input, bool throw_on_failure=false)
 Robust string to integer conversion that fails for cases such at "1foo". More...
 
void MooseUtils::linearPartitionItems (dof_id_type num_items, dof_id_type num_chunks, dof_id_type chunk_id, dof_id_type &num_local_items, dof_id_type &local_items_begin, dof_id_type &local_items_end)
 Linearly partition a number of items. More...
 
processor_id_type MooseUtils::linearPartitionChunk (dof_id_type num_items, dof_id_type num_chunks, dof_id_type item_id)
 Return the chunk_id that is assigned to handle item_id. More...
 
std::vector< std::string > MooseUtils::split (const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
 Python like split functions for strings. More...
 
std::vector< std::string > MooseUtils::rsplit (const std::string &str, const std::string &delimiter, std::size_t max_count=std::numeric_limits< std::size_t >::max())
 
void MooseUtils::createSymlink (const std::string &target, const std::string &link)
 Create a symbolic link, if the link already exists it is replaced. More...
 
void MooseUtils::clearSymlink (const std::string &link)
 Remove a symbolic link, if the given filename is a link. More...
 
std::size_t MooseUtils::fileSize (const std::string &filename)
 Check the file size. More...
 
std::string MooseUtils::realpath (const std::string &path)
 Wrapper around PetscGetRealPath, which is a cross-platform replacement for realpath. More...
 
BoundingBox MooseUtils::buildBoundingBox (const Point &p1, const Point &p2)
 Construct a valid bounding box from 2 arbitrary points. More...
 
std::string MooseUtils::prettyCppType (const std::string &cpp_type)
 
void removeSubstring (std::string &main, const std::string &sub)
 find, erase, length algorithm for removing a substring from a string More...
 
std::string removeSubstring (const std::string &main, const std::string &sub)
 find, erase, length algorithm for removing a substring from a copy of a string More...
 

Function Documentation

◆ removeSubstring() [1/2]

void removeSubstring ( std::string &  main,
const std::string &  sub 
)

find, erase, length algorithm for removing a substring from a string

Definition at line 1256 of file MooseUtils.C.

Referenced by FEProblemBase::checkDependMaterialsHelper(), and SubProblem::initialSetup().

1257 {
1258  std::string::size_type n = sub.length();
1259  for (std::string::size_type i = main.find(sub); i != std::string::npos; i = main.find(sub))
1260  main.erase(i, n);
1261 }
void main(int argc, char *argv[])
Initialize, create and run a MooseApp.
Definition: MooseMain.h:37

◆ removeSubstring() [2/2]

std::string removeSubstring ( const std::string &  main,
const std::string &  sub 
)

find, erase, length algorithm for removing a substring from a copy of a string

Definition at line 1264 of file MooseUtils.C.

1265 {
1266  std::string copy_main = main;
1267  std::string::size_type n = sub.length();
1268  for (std::string::size_type i = copy_main.find(sub); i != std::string::npos;
1269  i = copy_main.find(sub))
1270  copy_main.erase(i, n);
1271  return copy_main;
1272 }
void main(int argc, char *argv[])
Initialize, create and run a MooseApp.
Definition: MooseMain.h:37