BornAgain
1.19.79
Open-source research software to simulate and fit neutron and x-ray reflectometry and grazing-incidence small-angle scattering
|
Utility functions to analyze or modify strings.
Functions | |
std::string | join (const std::vector< std::string > &joinable, const std::string &joint) |
Returns string obtain by joining vector elements. More... | |
std::string | padRight (const std::string &name, size_t length) |
Returns string right-padded with blanks. More... | |
void | replaceItemsFromString (std::string &text, const std::vector< std::string > &items, const std::string &replacement="") |
Replaces all occurrences of items from string text with delimiter. More... | |
template<typename T > | |
std::string | scientific (T value, int n=10) |
Returns scientific string representing given value of any numeric type. More... | |
std::vector< std::string > | split (const std::string &text, const std::string &delimiter) |
Split string into vector of string using delimiter. More... | |
bool | startsWith (const std::string &str, const std::string &substr) |
True if the string starts with substr. The comparison is case sensitive. More... | |
bool | to_int (const std::string &str, int *result) |
Interprets the contained text as an integer and returns it in result. Space chars at its begin and end will be ignored. If the conversion result is of no interest, but only the convertibility, then you can set result to nullptr. The conversion is assumed to be successful if: More... | |
std::string | to_lower (std::string text) |
Returns new string which is lower case of text. More... | |
std::string | trim (const std::string &str, const std::string &whitespace=" \t") |
Cuts any of the chars given in whitespace from start and end of str. More... | |
std::string | trimFront (const std::string &str, const std::string &whitespace=" \t") |
Cuts any of the chars given in whitespace from start. More... | |
std::string BaseUtils::String::join | ( | const std::vector< std::string > & | joinable, |
const std::string & | joint | ||
) |
Returns string obtain by joining vector elements.
Definition at line 45 of file StringUtils.cpp.
Referenced by Py::Fmt::printArguments(), and Py::Fmt::printImportedSymbols().
std::string BaseUtils::String::padRight | ( | const std::string & | name, |
size_t | length | ||
) |
Returns string right-padded with blanks.
Definition at line 21 of file StringUtils.cpp.
Referenced by FitPrintService::parameterString().
void BaseUtils::String::replaceItemsFromString | ( | std::string & | text, |
const std::vector< std::string > & | items, | ||
const std::string & | replacement = "" |
||
) |
Replaces all occurrences of items from string text with delimiter.
Definition at line 37 of file StringUtils.cpp.
std::string BaseUtils::String::scientific | ( | T | value, |
int | n = 10 |
||
) |
Returns scientific string representing given value of any numeric type.
Definition at line 75 of file StringUtils.h.
References mumufit::stringUtils::scientific().
Referenced by FitPrintService::iterationHeaderString(), FitPrintService::parameterString(), Py::Fmt::printScientificDouble(), AttLimits::toString(), ReadWriteNumpyTXT::write1DRepresentation(), ReadWriteNumpyTXT::write2DRepresentation(), and ReadWriteINT::writeDatafieldDoubles().
std::vector< std::string > BaseUtils::String::split | ( | const std::string & | text, |
const std::string & | delimiter | ||
) |
Split string into vector of string using delimiter.
Returns token vector obtained by splitting string at delimiters.
Definition at line 29 of file StringUtils.cpp.
Referenced by IO::readNicosData(), and mumufit::stringUtils::split().
bool BaseUtils::String::startsWith | ( | const std::string & | str, |
const std::string & | substr | ||
) |
True if the string starts with substr. The comparison is case sensitive.
Definition at line 110 of file StringUtils.cpp.
Referenced by IO::readNicosData().
bool BaseUtils::String::to_int | ( | const std::string & | str, |
int * | result | ||
) |
Interprets the contained text as an integer and returns it in result. Space chars at its begin and end will be ignored. If the conversion result is of no interest, but only the convertibility, then you can set result to nullptr. The conversion is assumed to be successful if:
Definition at line 64 of file StringUtils.cpp.
Referenced by IO::readNicosData().
std::string BaseUtils::String::to_lower | ( | std::string | text | ) |
Returns new string which is lower case of text.
Definition at line 58 of file StringUtils.cpp.
Referenced by BaseUtils::Filesystem::hasExtension().
std::string BaseUtils::String::trim | ( | const std::string & | str, |
const std::string & | whitespace = " \t" |
||
) |
Cuts any of the chars given in whitespace from start and end of str.
Definition at line 87 of file StringUtils.cpp.
Referenced by ReadWriteINT::readDatafield(), ReadWriteNumpyTXT::readDatafield(), ReadReflectometry::readDatafield(), and IO::readNicosData().
std::string BaseUtils::String::trimFront | ( | const std::string & | str, |
const std::string & | whitespace = " \t" |
||
) |
Cuts any of the chars given in whitespace from start.
Definition at line 100 of file StringUtils.cpp.
Referenced by IO::readNicosData().