OGS 6.1.0-1699-ge946d4c5f
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 
78 std::string padLeft(std::string const& str, int maxlen, char ch=' ');
79 
80 
82 template<typename T> std::string tostring(T const& value)
83 {
84  return std::to_string(value);
85 }
87 std::string const& tostring(std::string const& value);
88 
90 std::string format(const char* format_string, ... );
91 
92 } // end namespace BaseLib
std::string padLeft(std::string const &str, int maxlen, char ch)
Definition: StringTools.cpp:79
std::string format(const char *format_str,...)
returns printf-like formatted string
Definition: StringTools.cpp:91
T str2number(const std::string &str)
Definition: StringTools.h:55
std::string const & tostring(std::string const &value)
Definition: StringTools.cpp:86
Build information.
void simplify(std::string &str)
Definition: StringTools.cpp:70
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:48
void trim(std::string &str, char ch)
Definition: StringTools.cpp:56