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[in] The string to split (not modified by call)

  • delim[in] The delimiter to split on (single char)

  • elems[inout] 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[in] The string to split (not modified by call)

  • delim[in] The delimiter to split on (single char)

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

Strips leading and trailing spaces from a string

Parameters
  • s[in] The string to trim (not modified)

  • c[in] Collection of characters to remove

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

Strips leading spaces from a string

Parameters
  • s[in] The string to trim (not modified)

  • c[in] Collection of characters to remove

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

Strips leading spaces from a string

Parameters
  • s[in] The string to trim (not modified)

  • c[in] Collection of characters to remove

std::string trimComments(const std::string &s, const std::string &c)

Strips the comments from a string

Parameters
  • s[in] The string to trim (not modified)

  • c[in] 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

std::string::size_type editDistance(const std::string &str1, const std::string &str2)

Returns the “edit distance” between two strings: how many insertions, deletions, substitutions and transpositions are needed to transform str1 into str2

Implemented using the “optimal string alignment distance” from Wikipedia: https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance#Optimal_string_alignment_distance