LevelS C++ support library  3.83
Functions
String handling helper functions

Functions

std::string trim (const std::string &orig)
 
template<typename T >
std::string dataToString (const T &x)
 
std::string intToString (int64 x, tsize width)
 
template<typename T >
void stringToData (const std::string &x, T &value)
 
template<typename T >
stringToData (const std::string &x)
 
void parse_file (const std::string &filename, std::map< std::string, std::string > &dict)
 
bool equal_nocase (const std::string &a, const std::string &b)
 
std::string tolower (const std::string &input)
 
template<typename T >
void split (const std::string &inp, std::vector< T > &list)
 
template<typename T >
std::vector< T > split (const std::string &inp)
 
void tokenize (const std::string &inp, char delim, std::vector< std::string > &list)
 
std::vector< std::string > tokenize (const std::string &inp, char delim)
 
void parse_words_from_file (const std::string &filename, std::vector< std::string > &words)
 

Detailed Description

Function Documentation

◆ trim()

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

Returns the string orig without leading and trailing whitespace.

◆ dataToString()

template<typename T >
std::string dataToString ( const T &  x)

Returns a string containing the text representation of x. Care is taken that no information is lost in the conversion.

Definition at line 52 of file string_utils.cc.

◆ intToString()

std::string intToString ( int64  x,
tsize  width 
)

Returns a string containing the text representation of x, padded with leading zeroes to width characters.

Definition at line 93 of file string_utils.cc.

◆ stringToData() [1/2]

template<typename T >
void stringToData ( const std::string &  x,
T &  value 
)

Reads a value of a given datatype from a string

◆ stringToData() [2/2]

template<typename T >
T stringToData ( const std::string &  x)
inline

Reads a value of a given datatype from a string

Definition at line 64 of file string_utils.h.

◆ parse_file()

void parse_file ( const std::string &  filename,
std::map< std::string, std::string > &  dict 
)

Parses the file filename and returns the key/value pairs in dict.

◆ equal_nocase()

bool equal_nocase ( const std::string &  a,
const std::string &  b 
)

Case-insensitive string comparison Returns true, if a and b differ only in capitalisation, else false.

◆ tolower()

std::string tolower ( const std::string &  input)

Returns lowercase version of input.

◆ split() [1/2]

template<typename T >
void split ( const std::string &  inp,
std::vector< T > &  list 
)

Tries to split inp into a white-space separated list of values of type T, and appends them to list.

◆ split() [2/2]

template<typename T >
std::vector<T> split ( const std::string &  inp)
inline

Tries to split inp into a white-space separated list of values of type T, and appends them to list.

Definition at line 99 of file string_utils.h.

◆ tokenize() [1/2]

void tokenize ( const std::string &  inp,
char  delim,
std::vector< std::string > &  list 
)

Breaks the string inp into tokens separated by delim, and returns them in list.

◆ tokenize() [2/2]

std::vector<std::string> tokenize ( const std::string &  inp,
char  delim 
)
inline

Breaks the string inp into tokens separated by delim, and returns them as a vector<string>.

Definition at line 109 of file string_utils.h.

◆ parse_words_from_file()

void parse_words_from_file ( const std::string &  filename,
std::vector< std::string > &  words 
)

Reads all white-space separated strings from filename, and returns them in words.


Generated on Wed Nov 13 2024 12:18:16 for LevelS C++ support library