File utils.cxx

Functions

char *copy_string(const char *s)

Allocate memory and copy string s

const std::string lowercase(const std::string &str)

Convert a string to lower case

const std::string uppercase(const std::string &str)

Convert a string to upper case

const std::string lowercasequote(const std::string &str)

Convert to lower case, except inside quotes (” or ‘)

BoutReal stringToReal(const std::string &s)

Convert a string to a BoutReal Throws BoutException if can’t be done

int stringToInt(const std::string &s)

Convert a string to an int

Throws BoutException if can’t be done

std::list<std::string> &strsplit(const std::string &s, char delim, std::list<std::string> &elems)

Split a string on a given delimiter

Parameters
  • s: The string to split (not modified by call)
  • delim: The delimiter to split on (single char)
  • elems: A list to which the pieces will be appended using push_back

std::list<std::string> strsplit(const std::string &s, char delim)

Split a string on a given delimiter

Parameters
  • s: The string to split (not modified by call)
  • delim: The delimiter to split on (single char)

std::string trim(const std::string &s)

Strips leading and trailing spaces from a string

Parameters
  • s: The string to trim (not modified)
  • c: Collection of characters to remove

std::string trimRight(const std::string &s)

Strips leading spaces from a string

Parameters
  • s: The string to trim (not modified)
  • c: Collection of characters to remove

std::string trimLeft(const std::string &s)

Strips leading spaces from a string

Parameters
  • s: The string to trim (not modified)
  • c: Collection of characters to remove

std::string trimComments(const std::string &s, const std::string &c = "#;")

Strips the comments from a string

Parameters
  • s: The string to trim (not modified)
  • c: Collection of characters to remove

std::string toString(const time_t &time)

Convert a time stamp to a string This uses std::localtime and std::put_time