9 #ifndef STRING_UTILITIES_H
10 #define STRING_UTILITIES_H
12 #include <argos3/core/utility/configuration/argos_exception.h>
13 #include <argos3/core/utility/datatypes/datatypes.h>
36 template<
typename T> std::string
ToString(
const T& t_value) {
37 std::ostringstream ss;
38 ss.setf(std::ios::boolalpha);
59 template<
typename T> T
FromString(
const std::string& str_value) {
61 std::istringstream ss(str_value);
62 ss.setf(std::ios::boolalpha);
70 template<
typename T>
void ParseValues(std::istream& str_input,
73 const char ch_delimiter =
'\n') {
74 std::vector<std::string> s(un_num_fields);
76 while(i < un_num_fields && std::getline(str_input, s[i], ch_delimiter)) {
79 if (i == un_num_fields) {
81 for(i = 0; i < un_num_fields; i++) {
82 std::istringstream iss(s[i]);
83 iss >> pt_field_buffer[i];
88 <<
" values, but " << i <<
" have been found in \""
89 << str_input.rdbuf() <<
"\"");
96 template<
typename T>
void ParseValues(
const std::string& str_input,
97 const UInt32 un_num_fields,
99 const char ch_delimiter =
'\n') {
100 std::istringstream issInput(str_input);
101 ParseValues(issInput, un_num_fields, pt_field_buffer, ch_delimiter);
113 void Tokenize(
const std::string& str_string,
114 std::vector<std::string>& vec_tokens,
115 const std::string& str_delimiters =
" ");
141 void Replace(std::string& str_buffer,
142 const std::string& str_original,
143 const std::string& str_new);
156 const std::string& str_pattern);
#define THROW_ARGOSEXCEPTION(message)
This macro throws an ARGoS exception with the passed message.
unsigned int UInt32
32-bit unsigned integer.
The namespace containing all the ARGoS related code.
void Replace(std::string &str_buffer, const std::string &str_original, const std::string &str_new)
Searches into str_buffer for occurrences of str_original and substitutes them with str_new.
std::string & ExpandEnvVariables(std::string &str_buffer)
Searches into str_buffer for occurrences of an environment variable of the form $VAR and substitutes ...
bool MatchPattern(const std::string &str_input, const std::string &str_pattern)
Returns true if str_pattern is matched by str_input.
void ParseValues(std::istream &str_input, UInt32 un_num_fields, T *pt_field_buffer, const char ch_delimiter='\n')
T FromString(const std::string &str_value)
Converts the given std::string parameter to the wanted type.
std::string StringToLowerCase(const std::string &str_string)
Converts a string to lower case.
void Tokenize(const std::string &str_string, std::vector< std::string > &vec_tokens, const std::string &str_delimiters)
Tokenizes the given string according to the wanted delimiters (by default just a " ").
std::string StringToUpperCase(const std::string &str_string)
Converts a string to upper case.
std::string ToString(const T &t_value)
Converts the given parameter to a std::string.