OGS 6.2.2-330-gf48c72f61.dirty.20200225212913
StringTools.h
Go to the documentation of this file.
1 
15 #pragma once
16 
17 #include <string>
18 #include <list>
19 #include <sstream>
20 #include <vector>
21 
22 namespace BaseLib {
30 std::vector<std::string> splitString(std::string const& str);
31 
38 std::list<std::string> splitString(const std::string &str, char delim);
39 
47 std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace);
48 
55 template<typename T> T str2number (const std::string &str)
56 {
57  std::stringstream strs (str, std::stringstream::in | std::stringstream::out);
58  T v;
59  strs >> v;
60  return v;
61 }
62 
67 void trim(std::string &str, char ch=' ');
68 
73 void simplify(std::string &str);
74 
76 template<typename T> std::string tostring(T const& value)
77 {
78  return std::to_string(value);
79 }
81 std::string const& tostring(std::string const& value);
82 
84 std::string format(const char* format_string, ... );
85 
86 } // end namespace BaseLib
std::string format(const char *format_str,...)
returns printf-like formatted string
Definition: StringTools.cpp:90
T str2number(const std::string &str)
Definition: StringTools.h:55
std::string const & tostring(std::string const &value)
Definition: StringTools.cpp:85
Functionality to build different search length algorithm objects from given config.
void simplify(std::string &str)
Definition: StringTools.cpp:76
std::vector< std::string > splitString(std::string const &str)
Definition: StringTools.cpp:28
std::string replaceString(const std::string &searchString, const std::string &replaceString, std::string stringToReplace)
Definition: StringTools.cpp:50
void trim(std::string &str, char ch)
Definition: StringTools.cpp:58